package v1

import (
	"kami/internal/consts"

	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/os/gtime"
)

// ====================================================================================
// Order Processing API
// ====================================================================================

type JdCookieOrderApi struct {
	CreateOrderReq       *CreateOrderReq       `path:"/jd-cookie/order/create" method:"post" summary:"Create Order" tags:"JD Order Management"`
	GetPaymentUrlReq     *GetPaymentUrlReq     `path:"/jd-cookie/order/payment-url" method:"post" summary:"Get Payment URL" tags:"JD Order Management"`
	GetOrderStatusReq    *GetOrderStatusReq    `path:"/jd-cookie/order/status" method:"get" summary:"Query Order Status" tags:"JD Order Management"`
	GetOrderReq          *GetOrderReq          `path:"/jd-cookie/order/get" method:"get" summary:"Get Single Order" tags:"JD Order Management"`
	GetJdOrderReq        *GetJdOrderReq        `path:"/jd-cookie/order/jd-order" method:"get" summary:"Get Single JD Order" tags:"JD Order Management"`
	ListOrderReq         *ListOrderReq         `path:"/jd-cookie/order/list" method:"get" summary:"Order List Query" tags:"JD Order Management"`
	ListJdOrderReq       *ListJdOrderReq       `path:"/jd-cookie/order/jd-list" method:"get" summary:"JD Order List Query" tags:"JD Order Management"`
	GetJdOrderHistoryReq *GetJdOrderHistoryReq `path:"/jd-cookie/order/jd-order-history" method:"get" summary:"Get JD Order History" tags:"JD Order Management"`
	ExportJdOrderReq     *ExportJdOrderReq     `path:"/jd-cookie/order/export" method:"get" summary:"Export JD Orders" tags:"JD Order Management"`
}

// ====================================================================================
// Order Processing Request/Response Structures
// ====================================================================================

// CreateOrderReq Create Order Request
type CreateOrderReq struct {
	g.Meta      `path:"/jd-cookie/order/create" method:"post" summary:"Create Order" tags:"JD Order Management"`
	UserOrderId string                         `json:"userOrderId" v:"required#用户订单号不能为空" dc:"用户订单号"`
	Amount      float64                        `json:"amount" v:"required|min:0.01#订单金额不能为空|订单金额必须大于0" dc:"订单金额"`
	Category    consts.RedeemOrderCardCategory `json:"category" v:"required#商品品类不能为空" dc:"商品品类"`
}

type CreateOrderRes struct {
	g.Meta    `mime:"application/json"`
	WxPayUrl  string `json:"wxPayUrl" dc:"微信支付链接"`
	JdOrderId string `json:"jdOrderId" dc:"京东订单号"`
	OrderId   string `json:"orderId" dc:"内部订单号"`
}

// GetPaymentUrlReq Get Payment URL Request
type GetPaymentUrlReq struct {
	g.Meta  `path:"/jd-cookie/order/payment-url" method:"post" summary:"Get Payment URL" tags:"JD Order Management"`
	OrderId string `json:"orderId" v:"required#订单号不能为空" dc:"订单号"`
}

type GetPaymentUrlRes struct {
	g.Meta    `mime:"application/json"`
	WxPayUrl  string `json:"wxPayUrl" dc:"微信支付链接"`
	JdOrderId string `json:"jdOrderId" dc:"京东订单号"`
	OrderId   string `json:"orderId" dc:"内部订单号"`
}

// GetOrderStatusReq Query Order Status Request
type GetOrderStatusReq struct {
	g.Meta  `path:"/jd-cookie/order/status" method:"get" summary:"Query Order Status" tags:"JD Order Management"`
	OrderId string `json:"orderId" v:"required#订单号不能为空" dc:"订单号"`
}

type GetOrderStatusRes struct {
	g.Meta `mime:"application/json"`
	Order  *OrderInfo `json:"order" dc:"订单信息"`
}

// GetOrderReq Get Single Order Request
type GetOrderReq struct {
	g.Meta  `path:"/jd-cookie/order/get" method:"get" summary:"Get Single Order" tags:"JD Order Management"`
	OrderId string `json:"orderId" v:"required#订单号不能为空" dc:"订单号"`
}

type GetOrderRes struct {
	g.Meta `mime:"application/json"`
	Order  *OrderInfo `json:"order" dc:"订单详情"`
}

// GetJdOrderReq Get Single JD Order Request
type GetJdOrderReq struct {
	g.Meta    `path:"/jd-cookie/order/jd-order" method:"get" summary:"Get Single JD Order" tags:"JD Order Management"`
	JdOrderId string `json:"jdOrderId" v:"required#京东订单号不能为空" dc:"京东订单号"`
}

type GetJdOrderRes struct {
	g.Meta `mime:"application/json"`
	Order  *JdOrderInfo `json:"order" dc:"京东订单详情"`
}

type OrderInfo struct {
	Id          int64              `json:"id" dc:"主键ID"`
	OrderId     string             `json:"orderId" dc:"订单号"`
	UserOrderId string             `json:"userOrderId" dc:"用户订单号"`
	Amount      float64            `json:"amount" dc:"订单金额"`
	Category    string             `json:"category" dc:"商品品类"`
	JdOrderId   string             `json:"jdOrderId" dc:"关联的京东订单号"`
	Status      consts.OrderStatus `json:"status" dc:"状态：1待支付 2已支付 3已过期 4已取消"`
	LastRequest *gtime.Time        `json:"lastRequestAt" dc:"最后请求时间"`
	CreatedAt   *gtime.Time        `json:"createdAt" dc:"创建时间"`
	UpdatedAt   *gtime.Time        `json:"updatedAt" dc:"更新时间"`
	DeletedAt   *gtime.Time        `json:"deletedAt" dc:"删除时间"`
}

type JdOrderInfo struct {
	Id              int64                `json:"id" dc:"主键ID"`
	JdOrderId       string               `json:"jdOrderId" dc:"京东订单号"`
	PayId           string               `json:"payId" dc:"支付ID"`
	Amount          float64              `json:"amount" dc:"订单金额"`
	Category        string               `json:"category" dc:"商品品类"`
	CookieId        string               `json:"cookieId" dc:"使用的Cookie ID"`
	Cookie          *CookieAccountInfo   `json:"cookie" dc:"关联的Cookie账户信息"`
	Status          consts.JdOrderStatus `json:"status" dc:"状态：1待支付 2已支付 3已过期 4已取消"`
	WxPayUrl        string               `json:"wxPayUrl" dc:"微信支付链接"`
	WxPayExpireAt   *gtime.Time          `json:"wxPayExpireAt" dc:"微信支付链接过期时间"`
	OrderExpireAt   *gtime.Time          `json:"orderExpireAt" dc:"订单过期时间(默认24小时)"`
	OrderId         string               `json:"orderId" dc:"关联的用户订单号"`
	PaidAt          *gtime.Time          `json:"paidAt" dc:"支付完成时间"`
	CardNo          string               `json:"cardNo" dc:"卡号"`
	CardPassword    string               `json:"cardPassword" dc:"卡密"`
	CardExtractedAt *gtime.Time          `json:"cardExtractedAt" dc:"卡密提取时间"`
	CreatedAt       *gtime.Time          `json:"createdAt" dc:"创建时间"`
	UpdatedAt       *gtime.Time          `json:"updatedAt" dc:"更新时间"`
	DeletedAt       *gtime.Time          `json:"deletedAt" dc:"删除时间"`
}

// ListOrderReq Order List Query Request
type ListOrderReq struct {
	g.Meta    `path:"/jd-cookie/order/list" method:"get" summary:"Order List Query" tags:"JD Order Management"`
	Page      int                `json:"page" d:"1" dc:"页码"`
	Size      int                `json:"size" d:"20" dc:"每页大小"`
	Status    consts.OrderStatus `json:"status" dc:"状态筛选"`
	StartTime string             `json:"startTime" dc:"开始时间"`
	EndTime   string             `json:"endTime" dc:"结束时间"`
}

type ListOrderRes struct {
	g.Meta `mime:"application/json"`
	List   []*OrderInfo `json:"list" dc:"订单列表"`
	Total  int          `json:"total" dc:"总数"`
}

// ListJdOrderReq JD Order List Query Request
type ListJdOrderReq struct {
	g.Meta    `path:"/jd-cookie/order/jd-list" method:"get" summary:"JD Order List Query" tags:"JD Order Management"`
	Page      int                  `json:"page" d:"1" dc:"页码"`
	Size      int                  `json:"size" d:"20" dc:"每页大小"`
	Status    consts.JdOrderStatus `json:"status" dc:"状态筛选"`
	StartTime string               `json:"startTime" dc:"开始时间"`
	EndTime   string               `json:"endTime" dc:"结束时间"`
	OrderId   string               `json:"orderId" dc:"关联的内部订单号筛选"`
}

type ListJdOrderRes struct {
	g.Meta `mime:"application/json"`
	List   []*JdOrderInfo `json:"list" dc:"京东订单列表"`
	Total  int            `json:"total" dc:"总数"`
}

// GetJdOrderHistoryReq Get JD Order History Request
type GetJdOrderHistoryReq struct {
	g.Meta    `path:"/jd-cookie/order/jd-order-history" method:"get" summary:"Get JD Order History" tags:"JD Order Management"`
	JdOrderId string `json:"jdOrderId" v:"required#京东订单号不能为空" dc:"京东订单号"`
	Page      int    `json:"page" d:"1" dc:"页码"`
	Size      int    `json:"size" d:"20" dc:"每页大小"`
}

type GetJdOrderHistoryRes struct {
	g.Meta `mime:"application/json"`
	List   []*JdOrderHistoryInfo `json:"list" dc:"京东订单历史列表"`
	Total  int                   `json:"total" dc:"总数"`
}

type JdOrderHistoryInfo struct {
	HistoryUuid string                   `json:"historyUuid" dc:"历史记录唯一标识"`
	JdOrderId   string                   `json:"jdOrderId" dc:"京东订单号"`
	ChangeType  consts.JdOrderChangeType `json:"changeType" dc:"变更类型：create,bind,unbind,pay,expire,invalid,replace"`
	OrderId     string                   `json:"orderId" dc:"关联的订单号"`
	WxPayUrl    string                   `json:"wxPayUrl" dc:"微信支付链接"`
	Remark      string                   `json:"remark" dc:"备注信息"`
	CreatedAt   *gtime.Time              `json:"createdAt" dc:"创建时间"`
}

// ExportJdOrderReq Export JD Orders Request
type ExportJdOrderReq struct {
	g.Meta    `path:"/jd-cookie/order/export" method:"get" summary:"Export JD Orders" tags:"JD Order Management"`
	Status    consts.JdOrderStatus `json:"status" dc:"状态筛选"`
	StartTime string               `json:"startTime" dc:"开始时间"`
	EndTime   string               `json:"endTime" dc:"结束时间"`
	OrderId   string               `json:"orderId" dc:"关联的内部订单号筛选"`
}

type ExportJdOrderRes struct {
	g.Meta `mime:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"`
}
