/**
 * 佣金相关配置
 */

import { CommissionStatus, WithdrawalStatus } from '@/types/api/commission'

// 佣金状态选项
export const COMMISSION_STATUS_OPTIONS = [
  { label: '已冻结', value: CommissionStatus.FROZEN, type: 'info' as const },
  { label: '解冻中', value: CommissionStatus.UNFREEZING, type: 'warning' as const },
  { label: '已发放', value: CommissionStatus.RELEASED, type: 'success' as const },
  { label: '已失效', value: CommissionStatus.INVALID, type: 'danger' as const },
  { label: '待人工修正', value: CommissionStatus.PENDING_CORRECTION, type: 'warning' as const }
]

// 提现状态选项
export const WITHDRAWAL_STATUS_OPTIONS = [
  { label: '待审核', value: WithdrawalStatus.PENDING, type: 'warning' as const },
  { label: '已通过', value: WithdrawalStatus.APPROVED, type: 'success' as const },
  { label: '已拒绝', value: WithdrawalStatus.REJECTED, type: 'danger' as const },
  { label: '已到账', value: WithdrawalStatus.COMPLETED, type: 'success' as const }
]

// 支付方式选项
export const PAYMENT_METHOD_OPTIONS = [
  { label: '银行卡', value: 'bank', icon: 'bank' },
  { label: '支付宝', value: 'alipay', icon: 'alipay' },
  { label: '微信', value: 'wechat', icon: 'wechat' }
]

// ========== 提现状态映射 ==========

// 提现状态映射 (1:待审核, 2:已通过, 3:已拒绝, 4:已到账)
export const WithdrawalStatusMap = {
  1: { label: '待审核', type: 'warning' as const, color: '#E6A23C' },
  2: { label: '已通过', type: 'success' as const, color: '#67C23A' },
  3: { label: '已拒绝', type: 'danger' as const, color: '#F56C6C' },
  4: { label: '已到账', type: 'success' as const, color: '#67C23A' }
}

// ========== 佣金状态映射 ==========

// 佣金状态映射 (1:已冻结, 2:解冻中, 3:已发放, 4:已失效, 99:待人工修正)
export const CommissionStatusMap = {
  1: { label: '已冻结', type: 'info' as const, color: '#909399' },
  2: { label: '解冻中', type: 'warning' as const, color: '#E6A23C' },
  3: { label: '已发放', type: 'success' as const, color: '#67C23A' },
  4: { label: '已失效', type: 'danger' as const, color: '#F56C6C' },
  99: { label: '待人工修正', type: 'warning' as const, color: '#E6A23C' }
}

// ========== 提现方式映射 ==========

// 提现方式映射 (alipay:支付宝, wechat:微信, bank:银行卡)
export const WithdrawalMethodMap = {
  alipay: { label: '支付宝', icon: 'alipay' },
  wechat: { label: '微信', icon: 'wechat' },
  bank: { label: '银行卡', icon: 'bank' }
}

// ========== 佣金来源映射 ==========

// 佣金来源映射 (cost_diff:成本差价, one_time:一次性佣金)
export const CommissionSourceMap = {
  cost_diff: { label: '成本差价', type: 'primary' as const },
  one_time: { label: '一次性佣金', type: 'success' as const }
}

// 佣金类型映射 (one_time:一次性佣金, long_term:长期佣金) - 兼容旧字段
export const CommissionTypeMap = {
  one_time: { label: '一次性佣金', type: 'primary' as const },
  long_term: { label: '长期佣金', type: 'success' as const }
}

// 获取佣金状态标签
export function getCommissionStatusLabel(status: CommissionStatus): string {
  const option = COMMISSION_STATUS_OPTIONS.find((item) => item.value === status)
  return option?.label || String(status)
}

// 获取佣金状态类型
export function getCommissionStatusType(status: CommissionStatus) {
  const option = COMMISSION_STATUS_OPTIONS.find((item) => item.value === status)
  return option?.type || 'info'
}

// 获取提现状态标签
export function getWithdrawalStatusLabel(status: WithdrawalStatus): string {
  const option = WITHDRAWAL_STATUS_OPTIONS.find((item) => item.value === status)
  return option?.label || String(status)
}

// 获取提现状态类型
export function getWithdrawalStatusType(status: WithdrawalStatus) {
  const option = WITHDRAWAL_STATUS_OPTIONS.find((item) => item.value === status)
  return option?.type || 'info'
}

// 获取支付方式标签
export function getPaymentMethodLabel(method: string): string {
  const option = PAYMENT_METHOD_OPTIONS.find((item) => item.value === method)
  return option?.label || method
}

// 获取佣金类型标签
export function getCommissionTypeLabel(type: string): string {
  const config = CommissionTypeMap[type as keyof typeof CommissionTypeMap]
  return config?.label || String(type)
}

// 获取佣金类型type
export function getCommissionTypeType(type: string) {
  const config = CommissionTypeMap[type as keyof typeof CommissionTypeMap]
  return config?.type || 'info'
}
