package dto

// ========================================
// 代理商资金概况查询 DTO
// ========================================

// ShopFundSummaryListReq 代理商资金概况列表查询请求
type ShopFundSummaryListReq struct {
	Page     int    `json:"page" query:"page" validate:"omitempty,min=1" minimum:"1" description:"页码（默认1）"`
	PageSize int    `json:"page_size" query:"page_size" validate:"omitempty,min=1,max=100" minimum:"1" maximum:"100" description:"每页数量（默认20，最大100）"`
	ShopName string `json:"shop_name" query:"shop_name" validate:"omitempty,max=100" maxLength:"100" description:"店铺名称（模糊查询）"`
	Username string `json:"username" query:"username" validate:"omitempty,max=50" maxLength:"50" description:"主账号用户名（模糊查询）"`
}

// ShopFundSummaryItem 代理商资金概况项（含预充值钱包和佣金钱包）
type ShopFundSummaryItem struct {
	ShopID                uint   `json:"shop_id" description:"店铺ID"`
	ShopName              string `json:"shop_name" description:"店铺名称"`
	ShopCode              string `json:"shop_code" description:"店铺编码"`
	Username              string `json:"username" description:"主账号用户名"`
	Phone                 string `json:"phone" description:"主账号手机号"`
	MainBalance           int64  `json:"main_balance" description:"预充值钱包余额（分）"`
	MainFrozenBalance     int64  `json:"main_frozen_balance" description:"预充值钱包冻结余额（分）"`
	CashAvailableBalance  int64  `json:"cash_available_balance" description:"现金可用金额（分），等于主钱包余额减冻结金额"`
	CreditEnabled         bool   `json:"credit_enabled" description:"是否启用主钱包信用额度"`
	CreditLimit           int64  `json:"credit_limit" description:"主钱包信用额度（分），关闭信用时为0"`
	AvailableBalance      int64  `json:"available_balance" description:"总可用金额（分），等于现金可用金额加生效信用额度"`
	IsInDebt              bool   `json:"is_in_debt" description:"主钱包账面余额是否为负数"`
	DebtAmount            int64  `json:"debt_amount" description:"主钱包欠款金额（分），仅取负账面余额绝对值"`
	Version               int    `json:"version" description:"主钱包当前版本号，并发写冲突后应重新查询"`
	TotalCommission       int64  `json:"total_commission" description:"累计佣金总额（分）"`
	WithdrawnCommission   int64  `json:"withdrawn_commission" description:"已提现佣金（分）"`
	UnwithdrawCommission  int64  `json:"unwithdraw_commission" description:"未提现佣金（分）"`
	FrozenCommission      int64  `json:"frozen_commission" description:"冻结中佣金（分）"`
	WithdrawingCommission int64  `json:"withdrawing_commission" description:"提现中佣金（分）"`
	AvailableCommission   int64  `json:"available_commission" description:"可提现佣金（分）"`
	CreatedAt             string `json:"created_at" description:"店铺创建时间"`
}

// ShopFundSummaryPageResult 代理商资金概况列表分页响应
type ShopFundSummaryPageResult struct {
	Items []ShopFundSummaryItem `json:"items" description:"代理商资金概况列表"`
	Total int64                 `json:"total" description:"总记录数"`
	Page  int                   `json:"page" description:"当前页码"`
	Size  int                   `json:"size" description:"每页数量"`
}

// ========================================
// 主钱包流水查询 DTO
// ========================================

// MainWalletTransactionListRequest 主钱包流水查询请求
type MainWalletTransactionListRequest struct {
	ShopID          uint   `json:"-" path:"shop_id" description:"店铺ID" required:"true"`
	Page            int    `json:"page" query:"page" validate:"omitempty,min=1" minimum:"1" description:"页码（默认1）"`
	PageSize        int    `json:"page_size" query:"page_size" validate:"omitempty,min=1,max=100" minimum:"1" maximum:"100" description:"每页数量（默认20，最大100）"`
	TransactionType string `json:"transaction_type" query:"transaction_type" validate:"omitempty,max=50" maxLength:"50" description:"交易类型过滤（recharge:充值入账, deduct:套餐扣款, refund:退款）"`
	StartDate       string `json:"start_date" query:"start_date" validate:"omitempty" description:"开始日期（YYYY-MM-DD）"`
	EndDate         string `json:"end_date" query:"end_date" validate:"omitempty" description:"结束日期（YYYY-MM-DD）"`
	AssetIdentifier string `json:"asset_identifier" query:"asset_identifier" validate:"omitempty,max=100" maxLength:"100" description:"资产标识精确检索（ICCID 或 设备虚拟号，非空时精确匹配）"`
}

// MainWalletTransactionItem 主钱包流水记录项
type MainWalletTransactionItem struct {
	ID                 uint   `json:"id" description:"流水记录ID"`
	TransactionType    string `json:"transaction_type" description:"交易类型（recharge:充值入账, deduct:套餐扣款, refund:退款）"`
	TransactionSubtype string `json:"transaction_subtype" description:"交易子类型（可为空）"`
	Amount             int64  `json:"amount" description:"变动金额（分，正数为入账，负数为扣款）"`
	BalanceBefore      int64  `json:"balance_before" description:"变动前余额（分）"`
	BalanceAfter       int64  `json:"balance_after" description:"变动后余额（分）"`
	AssetType          string `json:"asset_type" description:"资产类型（iot_card:物联网卡, device:设备，仅套餐扣款流水有值）"`
	AssetID            uint   `json:"asset_id" description:"资产ID（仅套餐扣款流水有值）"`
	AssetIdentifier    string `json:"asset_identifier" description:"资产标识快照（ICCID、IMEI或虚拟号，仅套餐扣款流水有值）"`
	Remark             string `json:"remark" description:"备注（可为空）"`
	CreatedAt          string `json:"created_at" description:"流水时间"`
}

// MainWalletTransactionListResponse 主钱包流水列表响应
type MainWalletTransactionListResponse struct {
	Items []MainWalletTransactionItem `json:"items" description:"流水记录列表"`
	Total int64                       `json:"total" description:"总记录数"`
	Page  int                         `json:"page" description:"当前页码"`
	Size  int                         `json:"size" description:"每页数量"`
}

// ========================================
// 代理商提现记录查询 DTO
// ========================================

// ShopWithdrawalRequestListReq 代理商提现记录查询请求
type ShopWithdrawalRequestListReq struct {
	ShopID       uint   `json:"-" params:"shop_id" path:"shop_id" validate:"required" description:"店铺ID"`
	Page         int    `json:"page" query:"page" validate:"omitempty,min=1" minimum:"1" description:"页码（默认1）"`
	PageSize     int    `json:"page_size" query:"page_size" validate:"omitempty,min=1,max=100" minimum:"1" maximum:"100" description:"每页数量（默认20，最大100）"`
	WithdrawalNo string `json:"withdrawal_no" query:"withdrawal_no" validate:"omitempty,max=50" maxLength:"50" description:"提现单号（精确查询）"`
	StartTime    string `json:"start_time" query:"start_time" validate:"omitempty" description:"申请开始时间（格式：2006-01-02 15:04:05）"`
	EndTime      string `json:"end_time" query:"end_time" validate:"omitempty" description:"申请结束时间（格式：2006-01-02 15:04:05）"`
}

// ShopWithdrawalRequestItem 代理商提现记录项
type ShopWithdrawalRequestItem struct {
	ID               uint   `json:"id" description:"提现申请ID"`
	WithdrawalNo     string `json:"withdrawal_no" description:"提现单号"`
	Amount           int64  `json:"amount" description:"提现金额（分）"`
	FeeRate          int64  `json:"fee_rate" description:"手续费比率（基点，100=1%）"`
	Fee              int64  `json:"fee" description:"手续费（分）"`
	ActualAmount     int64  `json:"actual_amount" description:"实际到账金额（分）"`
	Status           int    `json:"status" description:"状态 (1:待审核, 2:已通过, 3:已拒绝, 4:已到账)"`
	StatusName       string `json:"status_name" description:"状态名称"`
	ShopID           uint   `json:"shop_id" description:"店铺ID"`
	ShopName         string `json:"shop_name" description:"店铺名称"`
	ShopHierarchy    string `json:"shop_hierarchy" description:"店铺层级路径（格式：上上级_上级_本身，最多两层上级）"`
	ApplicantID      uint   `json:"applicant_id" description:"申请人账号ID"`
	ApplicantName    string `json:"applicant_name" description:"申请人用户名"`
	ProcessorID      *uint  `json:"processor_id,omitempty" description:"处理人账号ID"`
	ProcessorName    string `json:"processor_name,omitempty" description:"处理人用户名"`
	WithdrawalMethod string `json:"withdrawal_method" description:"提现方式 (alipay:支付宝, wechat:微信, bank:银行卡)"`
	PaymentType      string `json:"payment_type" description:"放款类型 (manual:人工打款)"`
	AccountName      string `json:"account_name" description:"收款账户名称"`
	AccountNumber    string `json:"account_number" description:"收款账号"`
	BankName         string `json:"bank_name,omitempty" description:"银行名称（银行卡提现时）"`
	RejectReason     string `json:"reject_reason,omitempty" description:"拒绝原因"`
	Remark           string `json:"remark,omitempty" description:"备注"`
	CreatedAt        string `json:"created_at" description:"申请时间"`
	ProcessedAt      string `json:"processed_at,omitempty" description:"处理时间"`
	PaidAt           string `json:"paid_at,omitempty" description:"到账时间"`
}

// ShopWithdrawalRequestPageResult 代理商提现记录分页响应
type ShopWithdrawalRequestPageResult struct {
	Items []ShopWithdrawalRequestItem `json:"items" description:"提现记录列表"`
	Total int64                       `json:"total" description:"总记录数"`
	Page  int                         `json:"page" description:"当前页码"`
	Size  int                         `json:"size" description:"每页数量"`
}

// ========================================
// 代理商佣金明细查询 DTO
// ========================================

// ShopCommissionRecordListReq 代理商佣金明细查询请求
type ShopCommissionRecordListReq struct {
	ShopID           uint   `json:"-" params:"shop_id" path:"shop_id" validate:"required" description:"店铺ID"`
	Page             int    `json:"page" query:"page" validate:"omitempty,min=1" minimum:"1" description:"页码（默认1）"`
	PageSize         int    `json:"page_size" query:"page_size" validate:"omitempty,min=1,max=100" minimum:"1" maximum:"100" description:"每页数量（默认20，最大100）"`
	CommissionSource string `json:"commission_source" query:"commission_source" validate:"omitempty,oneof=cost_diff one_time tier_bonus" description:"佣金来源 (cost_diff:成本价差, one_time:一次性佣金, tier_bonus(已废弃):梯度奖励)"`
	ICCID            string `json:"iccid" query:"iccid" validate:"omitempty,max=50" maxLength:"50" description:"ICCID（模糊查询）"`
	VirtualNo        string `json:"virtual_no" query:"virtual_no" validate:"omitempty,max=50" maxLength:"50" description:"设备虚拟号（模糊查询）"`
	OrderNo          string `json:"order_no" query:"order_no" validate:"omitempty,max=50" maxLength:"50" description:"订单号（模糊查询）"`
}

// ShopCommissionRecordItem 代理商佣金明细项
type ShopCommissionRecordItem struct {
	ID               uint   `json:"id" description:"佣金记录ID"`
	Amount           int64  `json:"amount" description:"佣金金额（分）"`
	BalanceAfter     int64  `json:"balance_after" description:"入账后佣金余额（分）"`
	CommissionSource string `json:"commission_source" description:"佣金来源 (cost_diff:成本价差, one_time:一次性佣金, tier_bonus(已废弃):梯度奖励)"`
	Status           int    `json:"status" description:"状态 (1:已冻结, 2:解冻中, 3:已发放, 4:已失效)"`
	StatusName       string `json:"status_name" description:"状态名称"`
	OrderID          uint   `json:"order_id" description:"订单ID"`
	OrderNo          string `json:"order_no" description:"订单号"`
	VirtualNo        string `json:"virtual_no,omitempty" description:"设备虚拟号"`
	ICCID            string `json:"iccid,omitempty" description:"ICCID"`
	OrderCreatedAt   string `json:"order_created_at" description:"订单创建时间"`
	SellerShopID     uint   `json:"seller_shop_id" description:"销售来源店铺ID"`
	SellerShopName   string `json:"seller_shop_name" description:"销售来源店铺名称"`
	CreatedAt        string `json:"created_at" description:"佣金入账时间"`
}

// ShopCommissionRecordPageResult 代理商佣金明细分页响应
type ShopCommissionRecordPageResult struct {
	Items []ShopCommissionRecordItem `json:"items" description:"佣金明细列表"`
	Total int64                      `json:"total" description:"总记录数"`
	Page  int                        `json:"page" description:"当前页码"`
	Size  int                        `json:"size" description:"每页数量"`
}

// ========================================
// 路由参数 DTO
// ========================================

// ShopIDPathParam 店铺ID路径参数
type ShopIDPathParam struct {
	ShopID uint `path:"shop_id" description:"店铺ID" required:"true"`
}
