/**
 * 退款管理相关类型定义
 */

// 退款状态
export enum RefundStatus {
  PENDING = 1, // 待审批
  APPROVED = 2, // 已通过
  REJECTED = 3, // 已拒绝
  RETURNED = 4 // 已退回
}

export interface RefundAttachment {
  file_key: string
  file_name?: string
  file_size?: number
}

export interface RefundApprovalTimelineItem {
  time?: string
  timestamp?: string
  status?: string
  status_name?: string
  operator?: string
  operator_name?: string
  comment?: string
  content?: string
  [key: string]: unknown
}

export interface RefundApproval {
  source?: string | null
  sp_no?: string | null
  status?: string | null
  status_name?: string | null
  template_version?: string | null
  applicant?: unknown
  approvers?: unknown[]
  comments?: unknown[]
  attachments?: RefundAttachment[]
  timeline?: RefundApprovalTimelineItem[]
  business_process_result?: unknown
}

// 退款申请
export interface Refund {
  id: number
  refund_no: string
  order_id: number
  order_no: string // 订单号
  shop_id: number
  shop_name: string // 店铺名称
  package_usage_id: number | null
  asset_identifier: string // 资产标识符
  asset_type: string // 资产类型
  requested_refund_amount?: number | null // 申请退款金额（分）
  approved_refund_amount?: number | null // 实际退款金额（分）
  actual_received_amount?: number | null // 实收金额（分）
  status: RefundStatus
  status_name?: string | null
  refund_reason: string
  refund_voucher_key?: string[] | string // 退款凭证附件列表；历史数据可能为单字符串或逗号字符串
  attachments?: RefundAttachment[]
  reject_reason: string
  remark: string
  asset_reset: boolean
  commission_deducted: boolean
  submitter_name?: string | null // 提交人名称
  approval_source?: 'none' | 'legacy' | 'wecom' | null // 审批来源
  approval_status?: string | null // 审批状态
  approval_status_name?: string | null // 审批状态名称
  current_approver_summary?: string | null // 当前审批人摘要
  processing_status?: string | null // 业务处理状态
  processing_status_name?: string | null // 业务处理状态名称
  processing_failure_summary?: string | null
  processing_message?: string | null
  business_process_result?: unknown
  approval?: RefundApproval | null
  creator: number
  processor_id: number | null
  processed_at: string | null
  created_at: string
  updated_at: string
  updater: number
}

// 查询退款申请列表参数
export interface RefundQueryParams {
  page?: number
  page_size?: number
  status?: RefundStatus
  order_id?: number
  shop_id?: number
  shop_name?: string // 店铺名称（模糊查询）
  asset_identifier?: string // 资产标识（ICCID 或 设备虚拟号，精确匹配）
  dateRange?: string[]
}

// 退款申请列表响应
export interface RefundListResponse {
  items: Refund[]
  page: number
  size: number
  total: number
}

// 创建退款申请请求
export interface CreateRefundRequest {
  order_id: number
  requested_refund_amount: number // 申请退款金额（分）
  actual_received_amount: number // 实收金额（分）
  attachments: RefundAttachment[]
  refund_reason?: string
  remark?: string
}

// 重新提交退款申请请求
export interface ResubmitRefundRequest {
  requested_refund_amount?: number
  actual_received_amount?: number
  attachments?: RefundAttachment[]
  refund_reason?: string
}
