syntax = "v1"

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

import "../types.api"

type (
	CreateCouponRequest {
		Name       string  `json:"name" validate:"required"`
		Code       string  `json:"code,omitempty"`
		Count      int64   `json:"count,omitempty"`
		Type       uint8   `json:"type" validate:"required"`
		Discount   int64   `json:"discount" validate:"required"`
		StartTime  int64   `json:"start_time" validate:"required"`
		ExpireTime int64   `json:"expire_time" validate:"required"`
		UserLimit  int64   `json:"user_limit,omitempty"`
		Subscribe  []int64 `json:"subscribe,omitempty"`
		UsedCount  int64   `json:"used_count,omitempty"`
		Enable     *bool   `json:"enable,omitempty"`
	}
	UpdateCouponRequest {
		Id         int64   `json:"id" validate:"required"`
		Name       string  `json:"name" validate:"required"`
		Code       string  `json:"code,omitempty"`
		Count      int64   `json:"count,omitempty"`
		Type       uint8   `json:"type" validate:"required"`
		Discount   int64   `json:"discount" validate:"required"`
		StartTime  int64   `json:"start_time" validate:"required"`
		ExpireTime int64   `json:"expire_time" validate:"required"`
		UserLimit  int64   `json:"user_limit,omitempty"`
		Subscribe  []int64 `json:"subscribe,omitempty"`
		UsedCount  int64   `json:"used_count,omitempty"`
		Enable     *bool   `json:"enable,omitempty"`
	}
	DeleteCouponRequest {
		Id int64 `json:"id" validate:"required"`
	}
	BatchDeleteCouponRequest {
		Ids []int64 `json:"ids" validate:"required"`
	}
	GetCouponListRequest {
		Page      int64  `form:"page" validate:"required"`
		Size      int64  `form:"size" validate:"required"`
		Subscribe int64  `form:"subscribe,omitempty"`
		Search    string `form:"search,omitempty"`
	}
	GetCouponListResponse {
		Total int64    `json:"total"`
		List  []Coupon `json:"list"`
	}
)

@server (
	prefix:     v1/admin/coupon
	group:      admin/coupon
	middleware: AuthMiddleware
)
service ppanel {
	@doc "Create coupon"
	@handler CreateCoupon
	post / (CreateCouponRequest)

	@doc "Update coupon"
	@handler UpdateCoupon
	put / (UpdateCouponRequest)

	@doc "Delete coupon"
	@handler DeleteCoupon
	delete / (DeleteCouponRequest)

	@doc "Batch delete coupon"
	@handler BatchDeleteCoupon
	delete /batch (BatchDeleteCouponRequest)

	@doc "Get coupon list"
	@handler GetCouponList
	get /list (GetCouponListRequest) returns (GetCouponListResponse)
}

