syntax = "v1"

info (
	title:   "promo admin API"
	desc:    "API for ppanel"
	author:  "Tension"
	email:   "tension@ppanel.com"
	version: "0.0.1"
)

import "../types.api"

type (
	CreatePromoRuleRequest {
		Name      string                 `json:"name" validate:"required,max=100"`
		Type      string                 `json:"type" validate:"required,oneof=new_user inactive_user campaign"`
		Params    map[string]interface{} `json:"params"`
		Priority  int64                  `json:"priority" validate:"gte=0"`
		Enabled   *bool                  `json:"enabled"`
		StartTime *int64                 `json:"start_time"`
		EndTime   *int64                 `json:"end_time"`
	}
	UpdatePromoRuleRequest {
		Id        int64                  `uri:"id" validate:"required,gt=0"`
		Name      string                 `json:"name" validate:"required,max=100"`
		Type      string                 `json:"type" validate:"required,oneof=new_user inactive_user campaign"`
		Params    map[string]interface{} `json:"params"`
		Priority  int64                  `json:"priority" validate:"gte=0"`
		Enabled   *bool                  `json:"enabled"`
		StartTime *int64                 `json:"start_time"`
		EndTime   *int64                 `json:"end_time"`
	}
	GetPromoRuleDetailRequest {
		Id int64 `uri:"id" validate:"required,gt=0"`
	}
	DeletePromoRuleRequest {
		Id int64 `uri:"id" validate:"required,gt=0"`
	}
	GetPromoRuleListRequest {
		Page    int64  `form:"page" validate:"required,gt=0"`
		Size    int64  `form:"size" validate:"required,gt=0,lte=200"`
		Type    string `form:"type" validate:"omitempty,oneof=new_user inactive_user campaign"`
		Enabled *bool  `form:"enabled"`
		Search  string `form:"search,omitempty"`
	}
	GetPromoRuleListResponse {
		Total int64       `json:"total"`
		List  []PromoRule `json:"list"`
	}
	SetPromoPriceRequest {
		PromoRuleId int64            `json:"promo_rule_id" validate:"required,gt=0"`
		Items       []PromoPriceItem `json:"items" validate:"required,min=1,dive"`
	}
	GetPromoPriceListRequest {
		Page        int64 `form:"page" validate:"required,gt=0"`
		Size        int64 `form:"size" validate:"required,gt=0,lte=200"`
		RuleId      int64 `form:"rule_id,omitempty"`
		SubscribeId int64 `form:"subscribe_id,omitempty"`
	}
	GetPromoPriceListResponse {
		Total int64        `json:"total"`
		List  []PromoPrice `json:"list"`
	}
	DeletePromoPriceRequest {
		Id int64 `uri:"id" validate:"required,gt=0"`
	}
	GetPromoUsageListRequest {
		Page        int64  `form:"page" validate:"required,gt=0"`
		Size        int64  `form:"size" validate:"required,gt=0,lte=200"`
		RuleId      int64  `form:"rule_id,omitempty"`
		UserId      int64  `form:"user_id,omitempty"`
		SubscribeId int64  `form:"subscribe_id,omitempty"`
		OrderNo     string `form:"order_no,omitempty"`
	}
	GetPromoUsageListResponse {
		Total int64        `json:"total"`
		List  []PromoUsage `json:"list"`
	}
)

@server (
	prefix:     v1/admin/promo
	group:      admin/promo
	middleware: AuthMiddleware
)
service ppanel {
	@doc "Create promo rule"
	@handler CreateRule
	post /rule (CreatePromoRuleRequest) returns (PromoRule)

	@doc "Get promo rule list"
	@handler GetRuleList
	get /rule/list (GetPromoRuleListRequest) returns (GetPromoRuleListResponse)

	@doc "Get promo rule detail"
	@handler GetRuleDetail
	get /rule/:id (GetPromoRuleDetailRequest) returns (PromoRule)

	@doc "Update promo rule"
	@handler UpdateRule
	put /rule/:id (UpdatePromoRuleRequest) returns (PromoRule)

	@doc "Delete promo rule"
	@handler DeleteRule
	delete /rule/:id (DeletePromoRuleRequest)

	@doc "Set promo prices"
	@handler SetPrice
	post /price (SetPromoPriceRequest)

	@doc "Get promo price list"
	@handler GetPriceList
	get /price/list (GetPromoPriceListRequest) returns (GetPromoPriceListResponse)

	@doc "Delete promo price"
	@handler DeletePrice
	delete /price/:id (DeletePromoPriceRequest)

	@doc "Get promo usage list"
	@handler GetUsageList
	get /usage/list (GetPromoUsageListRequest) returns (GetPromoUsageListResponse)
}
