syntax = "v1"

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

import "../types.api"

type (
	CreateOrderRequest {
		UserId         int64  `json:"user_id" validate:"required"`
		Type           uint8  `json:"type" validate:"required"`
		Quantity       int64  `json:"quantity,omitempty"`
		Price          int64  `json:"price" validate:"required"`
		Amount         int64  `json:"amount" validate:"required"`
		Discount       int64  `json:"discount,omitempty"`
		Coupon         string `json:"coupon,omitempty"`
		CouponDiscount int64  `json:"coupon_discount,omitempty"`
		Commission     int64  `json:"commission"`
		FeeAmount      int64  `json:"fee_amount" validate:"required"`
		PaymentId      int64  `json:"payment_id" validate:"required"`
		TradeNo        string `json:"trade_no,omitempty"`
		Status         uint8  `json:"status,omitempty"`
		SubscribeId    int64  `json:"subscribe_id,omitempty"`
	}
	UpdateOrderStatusRequest {
		Id        int64  `json:"id" validate:"required"`
		Status    uint8  `json:"status" validate:"required"`
		PaymentId int64  `json:"payment_id,omitempty"`
		TradeNo   string `json:"trade_no,omitempty"`
	}
	GetOrderListRequest {
		Page        int64  `form:"page" validate:"required"`
		Size        int64  `form:"size" validate:"required"`
		UserId      int64  `form:"user_id,omitempty"`
		Status      uint8  `form:"status,omitempty"`
		SubscribeId int64  `form:"subscribe_id,omitempty"`
		Search      string `form:"search,omitempty"`
	}
	GetOrderListResponse {
		Total int64   `json:"total"`
		List  []Order `json:"list"`
	}
)

@server (
	prefix:     v1/admin/order
	group:      admin/order
	middleware: AuthMiddleware
)
service ppanel {
	@doc "Create order"
	@handler CreateOrder
	post / (CreateOrderRequest)

	@doc "Get order list"
	@handler GetOrderList
	get /list (GetOrderListRequest) returns (GetOrderListResponse)

	@doc "Update order status"
	@handler UpdateOrderStatus
	put /status (UpdateOrderStatusRequest)
}

