package dto

import "time"

type CreateOrderRequest struct {
	OrderType     string `json:"order_type" validate:"required,oneof=single_card device" required:"true" description:"订单类型 (single_card:单卡购买, device:设备购买)"`
	IotCardID     *uint  `json:"iot_card_id" validate:"required_if=OrderType single_card" description:"IoT卡ID(单卡购买时必填)"`
	DeviceID      *uint  `json:"device_id" validate:"required_if=OrderType device" description:"设备ID(设备购买时必填)"`
	PackageIDs    []uint `json:"package_ids" validate:"required,min=1,max=10,dive,min=1" required:"true" minItems:"1" maxItems:"10" description:"套餐ID列表"`
	PaymentMethod string `json:"payment_method" validate:"required,oneof=wallet offline" required:"true" description:"支付方式 (wallet:钱包支付, offline:线下支付)"`
}

type OrderListRequest struct {
	Page          int        `json:"page" query:"page" validate:"omitempty,min=1" minimum:"1" description:"页码"`
	PageSize      int        `json:"page_size" query:"page_size" validate:"omitempty,min=1,max=100" minimum:"1" maximum:"100" description:"每页数量"`
	PaymentStatus *int       `json:"payment_status" query:"payment_status" validate:"omitempty,min=1,max=4" minimum:"1" maximum:"4" description:"支付状态 (1:待支付, 2:已支付, 3:已取消, 4:已退款)"`
	OrderType     string     `json:"order_type" query:"order_type" validate:"omitempty,oneof=single_card device" description:"订单类型 (single_card:单卡购买, device:设备购买)"`
	OrderNo       string     `json:"order_no" query:"order_no" validate:"omitempty,max=30" maxLength:"30" description:"订单号(精确查询)"`
	StartTime     *time.Time `json:"start_time" query:"start_time" description:"创建时间起始"`
	EndTime       *time.Time `json:"end_time" query:"end_time" description:"创建时间结束"`
}

type PayOrderRequest struct {
	PaymentMethod string `json:"payment_method" validate:"required,oneof=wallet wechat alipay" required:"true" description:"支付方式 (wallet:钱包支付, wechat:微信支付, alipay:支付宝支付)"`
}

type OrderItemResponse struct {
	ID          uint   `json:"id" description:"明细ID"`
	PackageID   uint   `json:"package_id" description:"套餐ID"`
	PackageName string `json:"package_name" description:"套餐名称"`
	Quantity    int    `json:"quantity" description:"数量"`
	UnitPrice   int64  `json:"unit_price" description:"单价(分)"`
	Amount      int64  `json:"amount" description:"小计金额(分)"`
}

type OrderResponse struct {
	ID                      uint                 `json:"id" description:"订单ID"`
	OrderNo                 string               `json:"order_no" description:"订单号"`
	OrderType               string               `json:"order_type" description:"订单类型 (single_card:单卡购买, device:设备购买)"`
	BuyerType               string               `json:"buyer_type" description:"买家类型 (personal:个人客户, agent:代理商)"`
	BuyerID                 uint                 `json:"buyer_id" description:"买家ID"`
	IotCardID               *uint                `json:"iot_card_id,omitempty" description:"IoT卡ID"`
	DeviceID                *uint                `json:"device_id,omitempty" description:"设备ID"`
	TotalAmount             int64                `json:"total_amount" description:"订单总金额(分)"`
	PaymentMethod           string               `json:"payment_method,omitempty" description:"支付方式 (wallet:钱包支付, wechat:微信支付, alipay:支付宝支付)"`
	PaymentStatus           int                  `json:"payment_status" description:"支付状态 (1:待支付, 2:已支付, 3:已取消, 4:已退款)"`
	PaymentStatusText       string               `json:"payment_status_text" description:"支付状态文本"`
	PaidAt                  *time.Time           `json:"paid_at,omitempty" description:"支付时间"`
	IsPurchaseOnBehalf      bool                 `json:"is_purchase_on_behalf" description:"是否为代购订单"`
	CommissionStatus        int                  `json:"commission_status" description:"佣金状态 (1:待计算, 2:已计算)"`
	CommissionConfigVersion int                  `json:"commission_config_version" description:"佣金配置版本"`
	Items                   []*OrderItemResponse `json:"items" description:"订单明细列表"`
	CreatedAt               time.Time            `json:"created_at" description:"创建时间"`
	UpdatedAt               time.Time            `json:"updated_at" description:"更新时间"`
}

type OrderListResponse struct {
	List       []*OrderResponse `json:"list" description:"订单列表"`
	Total      int64            `json:"total" description:"总数"`
	Page       int              `json:"page" description:"当前页码"`
	PageSize   int              `json:"page_size" description:"每页数量"`
	TotalPages int              `json:"total_pages" description:"总页数"`
}

type GetOrderRequest struct {
	ID uint `path:"id" description:"订单ID" required:"true"`
}

type CancelOrderRequest struct {
	ID uint `path:"id" description:"订单ID" required:"true"`
}

type PayOrderParams struct {
	ID uint `path:"id" description:"订单ID" required:"true"`
	PayOrderRequest
}

type PurchaseCheckRequest struct {
	OrderType  string `json:"order_type" validate:"required,oneof=single_card device" required:"true" description:"订单类型 (single_card:单卡购买, device:设备购买)"`
	ResourceID uint   `json:"resource_id" validate:"required,min=1" required:"true" description:"资源ID (IoT卡ID或设备ID)"`
	PackageIDs []uint `json:"package_ids" validate:"required,min=1,max=10,dive,min=1" required:"true" minItems:"1" maxItems:"10" description:"套餐ID列表"`
}

type PurchaseCheckResponse struct {
	TotalPackageAmount  int64  `json:"total_package_amount" description:"套餐总价(分)"`
	NeedForceRecharge   bool   `json:"need_force_recharge" description:"是否需要强充"`
	ForceRechargeAmount int64  `json:"force_recharge_amount" description:"强充金额(分)"`
	ActualPayment       int64  `json:"actual_payment" description:"实际支付金额(分)"`
	WalletCredit        int64  `json:"wallet_credit" description:"钱包到账金额(分)"`
	Message             string `json:"message" description:"提示信息"`
}
