/**
 * 法币提现相关类型定义
 */

/** 法币提现状态 */
export type FiatWithdrawalStatus =
  | 'PENDING'
  | 'FROZEN'
  | 'REVIEWING'
  | 'APPROVED'
  | 'PAYING'
  | 'COMPLETED'
  | 'REJECTED'
  | 'FAILED'
  | 'CANCELLED';

/** 支付方式 */
export type PaymentMethod = 'BANK_CARD' | 'ALIPAY' | 'WECHAT';

/** 法币提现订单 */
export interface FiatWithdrawalOrder {
  id: number;
  orderNo: string;
  accountSequence: string;
  userId: number;
  amount: string;
  fee: string;
  paymentMethod: PaymentMethod;
  // 银行卡信息
  bankName?: string;
  bankCardNo?: string;
  cardHolderName?: string;
  // 支付宝信息
  alipayAccount?: string;
  alipayRealName?: string;
  // 微信信息
  wechatAccount?: string;
  wechatRealName?: string;
  // 状态信息
  status: FiatWithdrawalStatus;
  errorMessage?: string;
  // 审核信息
  reviewedBy?: string;
  reviewedAt?: string;
  reviewRemark?: string;
  // 打款信息
  paidBy?: string;
  paidAt?: string;
  paymentProof?: string;
  paymentRemark?: string;
  // 详情备注
  detailMemo?: string;
  // 时间戳
  frozenAt?: string;
  completedAt?: string;
  createdAt: string;
}

/** 法币提现列表响应 */
export interface FiatWithdrawalListResponse {
  items: FiatWithdrawalOrder[];
  total: number;
  page: number;
  limit: number;
}

/** 查询参数 */
export interface QueryFiatWithdrawalsParams {
  status?: FiatWithdrawalStatus;
  paymentMethod?: PaymentMethod;
  accountSequence?: string;
  page?: number;
  limit?: number;
}

/** 审核请求 */
export interface ReviewFiatWithdrawalRequest {
  approved: boolean;
  remark?: string;
}

/** 开始打款请求 */
export interface StartPaymentRequest {
  remark?: string;
}

/** 完成打款请求 */
export interface CompletePaymentRequest {
  paymentProof?: string;
  remark?: string;
}

/** 状态信息 */
export interface StatusInfo {
  label: string;
  color: string;
}

/** 法币提现状态选项 */
export const FIAT_WITHDRAWAL_STATUS_OPTIONS: Array<{ value: FiatWithdrawalStatus; label: string }> = [
  { value: 'PENDING', label: '待处理' },
  { value: 'FROZEN', label: '已冻结' },
  { value: 'REVIEWING', label: '审核中' },
  { value: 'APPROVED', label: '已审核' },
  { value: 'PAYING', label: '打款中' },
  { value: 'COMPLETED', label: '已完成' },
  { value: 'REJECTED', label: '已拒绝' },
  { value: 'FAILED', label: '失败' },
  { value: 'CANCELLED', label: '已取消' },
];

/** 支付方式选项 */
export const PAYMENT_METHOD_OPTIONS: Array<{ value: PaymentMethod; label: string }> = [
  { value: 'BANK_CARD', label: '银行卡' },
  { value: 'ALIPAY', label: '支付宝' },
  { value: 'WECHAT', label: '微信' },
];

/** 获取法币提现状态信息 */
export function getFiatWithdrawalStatusInfo(status: FiatWithdrawalStatus): StatusInfo {
  const statusMap: Record<FiatWithdrawalStatus, StatusInfo> = {
    PENDING: { label: '待处理', color: '#faad14' },
    FROZEN: { label: '已冻结', color: '#722ed1' },
    REVIEWING: { label: '审核中', color: '#1677ff' },
    APPROVED: { label: '已审核', color: '#13c2c2' },
    PAYING: { label: '打款中', color: '#eb2f96' },
    COMPLETED: { label: '已完成', color: '#52c41a' },
    REJECTED: { label: '已拒绝', color: '#ff4d4f' },
    FAILED: { label: '失败', color: '#ff4d4f' },
    CANCELLED: { label: '已取消', color: '#8c8c8c' },
  };
  return statusMap[status] || { label: status, color: '#8c8c8c' };
}

/** 获取支付方式标签 */
export function getPaymentMethodLabel(method: PaymentMethod): string {
  const methodMap: Record<PaymentMethod, string> = {
    BANK_CARD: '银行卡',
    ALIPAY: '支付宝',
    WECHAT: '微信',
  };
  return methodMap[method] || method;
}
