package dto

// CreateRefundRequest 创建退款申请请求
type CreateRefundRequest struct {
	OrderID               uint     `json:"order_id" validate:"required" required:"true" description:"关联订单ID"`
	ActualReceivedAmount  int64    `json:"actual_received_amount" validate:"required,min=1" required:"true" minimum:"1" description:"实收金额（分）"`
	RequestedRefundAmount int64    `json:"requested_refund_amount" validate:"required,min=1" required:"true" minimum:"1" description:"申请退款金额（分）"`
	RefundVoucherKey      []string `json:"refund_voucher_key" validate:"required,min=1,max=5,dive,max=500" required:"true" minItems:"1" maxItems:"5" description:"退款凭证对象存储file_key列表（至少1个，最多5个，通过/storage/upload-url上传图片后获得）"`
	RefundReason          string   `json:"refund_reason" validate:"omitempty,max=1000" maxLength:"1000" description:"退款原因"`
	PackageUsageID        *uint    `json:"package_usage_id" validate:"omitempty" description:"关联套餐使用记录ID（可选）"`
}

// RefundIDRequest 退款申请ID路径参数
type RefundIDRequest struct {
	ID uint `path:"id" description:"退款申请ID" required:"true"`
}

// RejectRefundRequest 拒绝退款申请请求
type RejectRefundRequest struct {
	ID           uint   `json:"-" params:"id" path:"id" validate:"required" description:"退款申请ID"`
	RejectReason string `json:"reject_reason" validate:"required,max=500" required:"true" maxLength:"500" description:"拒绝原因（必填）"`
}

// ResubmitRefundRequest 重新提交退款申请请求
// 退款单被退回后，可修改部分字段后重新提交
type ResubmitRefundRequest struct {
	ID                    uint      `json:"-" params:"id" path:"id" validate:"required" description:"退款申请ID"`
	ActualReceivedAmount  *int64    `json:"actual_received_amount" validate:"omitempty,min=1" minimum:"1" description:"实收金额（分）"`
	RequestedRefundAmount *int64    `json:"requested_refund_amount" validate:"omitempty,min=1" minimum:"1" description:"申请退款金额（分）"`
	RefundVoucherKey      *[]string `json:"refund_voucher_key" validate:"omitempty,max=5,dive,max=500" maxItems:"5" description:"退款凭证对象存储file_key列表（重新提交时可替换；历史记录缺失时必填，最多5个）"`
	RefundReason          *string   `json:"refund_reason" validate:"omitempty,max=1000" maxLength:"1000" description:"退款原因"`
}

// ApproveRefundRequest 审批通过退款申请请求
type ApproveRefundRequest struct {
	ID                   uint   `json:"-" params:"id" path:"id" validate:"required" description:"退款申请ID"`
	ApprovedRefundAmount *int64 `json:"approved_refund_amount" validate:"omitempty,min=1" minimum:"1" description:"审批实际退款金额（分），不填则使用申请金额"`
	Remark               string `json:"remark" validate:"omitempty,max=500" maxLength:"500" description:"审批备注"`
}

// ReturnRefundRequest 退回退款申请请求
type ReturnRefundRequest struct {
	ID     uint   `json:"-" params:"id" path:"id" validate:"required" description:"退款申请ID"`
	Remark string `json:"remark" validate:"omitempty,max=500" maxLength:"500" description:"退回备注"`
}

// RefundListRequest 退款申请列表查询请求
type RefundListRequest 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）"`
	Status          *int   `json:"status" query:"status" validate:"omitempty,min=1,max=4" minimum:"1" maximum:"4" description:"状态 (1:待审批, 2:已通过, 3:已拒绝, 4:已退回)"`
	OrderID         *uint  `json:"order_id" query:"order_id" validate:"omitempty" description:"关联订单ID"`
	ShopID          *uint  `json:"shop_id" query:"shop_id" validate:"omitempty" description:"店铺ID"`
	AssetIdentifier string `json:"asset_identifier" query:"asset_identifier" validate:"omitempty,max=100" maxLength:"100" description:"资产标识精确检索（ICCID 或 设备虚拟号，非空时精确匹配）"`
}

// RefundResponse 退款申请详情响应
type RefundResponse struct {
	ID                    uint     `json:"id" description:"退款申请ID"`
	RefundNo              string   `json:"refund_no" description:"退款单号"`
	OrderID               uint     `json:"order_id" description:"关联订单ID"`
	OrderNo               string   `json:"order_no" description:"订单号"`
	AssetIdentifier       string   `json:"asset_identifier,omitempty" description:"下单时资产的标识符快照（卡为 ICCID，设备优先使用 VirtualNo，缺失时使用 IMEI）"`
	AssetType             string   `json:"asset_type,omitempty" description:"资产类型 (card:单卡, device:设备)"`
	IotCardID             *uint    `json:"iot_card_id,omitempty" description:"IoT卡ID"`
	DeviceID              *uint    `json:"device_id,omitempty" description:"设备ID"`
	PackageUsageID        *uint    `json:"package_usage_id,omitempty" description:"关联套餐使用记录ID"`
	ShopID                *uint    `json:"shop_id,omitempty" description:"店铺ID"`
	ShopName              string   `json:"shop_name,omitempty" description:"店铺名称"`
	ActualReceivedAmount  int64    `json:"actual_received_amount" description:"实收金额（分）"`
	RequestedRefundAmount int64    `json:"requested_refund_amount" description:"申请退款金额（分）"`
	ApprovedRefundAmount  *int64   `json:"approved_refund_amount,omitempty" description:"审批实际退款金额（分）"`
	RefundVoucherKey      []string `json:"refund_voucher_key" description:"退款凭证对象存储file_key列表（最多5个）"`
	RefundReason          string   `json:"refund_reason" description:"退款原因"`
	Status                int      `json:"status" description:"状态 (1:待审批, 2:已通过, 3:已拒绝, 4:已退回)"`
	StatusName            string   `json:"status_name" description:"状态名称（中文）"`
	ProcessorID           *uint    `json:"processor_id,omitempty" description:"审批人ID"`
	ProcessedAt           string   `json:"processed_at,omitempty" description:"审批时间"`
	RejectReason          string   `json:"reject_reason,omitempty" description:"拒绝原因"`
	Remark                string   `json:"remark,omitempty" description:"审批备注"`
	CommissionDeducted    bool     `json:"commission_deducted" description:"佣金是否已回扣"`
	AssetReset            bool     `json:"asset_reset" description:"退款后资产处理是否完成"`
	SubmitterID           uint     `json:"submitter_id" description:"提交人账号ID"`
	SubmitterName         string   `json:"submitter_name" description:"提交人账号名称"`
	ApprovalInstanceID    *uint    `json:"approval_instance_id,omitempty" description:"通用审批实例ID"`
	ApprovalProvider      string   `json:"approval_provider,omitempty" description:"审批渠道，企业微信为wecom"`
	ApprovalStatus        *int     `json:"approval_status,omitempty" description:"审批状态 (0:提交中, 1:审批中, 2:已通过, 3:已拒绝, 4:已撤销, 5:通过后撤销, 6:已删除, 7:提交失败, 8:提交结果未知)"`
	ApprovalStatusName    string   `json:"approval_status_name,omitempty" description:"审批状态名称（中文）"`
	Creator               uint     `json:"creator" description:"创建人ID"`
	Updater               uint     `json:"updater" description:"更新人ID"`
	CreatedAt             string   `json:"created_at" description:"创建时间"`
	UpdatedAt             string   `json:"updated_at" description:"更新时间"`
}

// RefundListResponse 退款申请列表分页响应
type RefundListResponse struct {
	Items []RefundResponse `json:"items" description:"退款申请列表"`
	Total int64            `json:"total" description:"总记录数"`
	Page  int              `json:"page" description:"当前页码"`
	Size  int              `json:"size" description:"每页数量"`
}
