import type {
  BalanceType,
  DisputeStatus,
  HandoffStatus,
  LedgerDirection,
  ListingReviewStatus,
  ListingStatus,
  OrderStatus,
  RealnameStatusValue,
  RiskStatus,
  SettlementStatus,
  UserStatus,
  WalletStatus,
} from '@/types/status'

const listingStatusMap: Record<ListingStatus, string> = {
  draft: '草稿',
  published: '已上架',
  rented: '租用中',
  offline: '已下架',
  abnormal: '异常',
}

const listingReviewStatusMap: Record<ListingReviewStatus, string> = {
  none: '未提交',
  pending: '待审核',
  approved: '已通过',
  rejected: '已拒绝',
}

const orderStatusMap: Record<OrderStatus, string> = {
  pending_confirm: '待确认',
  pending_payment: '待支付',
  pending_handoff: '待交接',
  renting: '使用中',
  overdue: '已逾期',
  pending_return_confirm: '待结账确认',
  pending_checkout_confirm: '待号主确认结账',
  pending_checkout_accept: '待租客确认修正',
  checkout_disputing: '结账争议中',
  completed: '已完成',
  cancelled: '已取消',
  closed: '已关闭',
  disputing: '申诉中',
  abnormal: '异常',
}

const handoffStatusMap: Record<HandoffStatus, string> = {
  pending_owner: '待号主交接',
  pending_renter_confirm: '待租客确认',
  received: '已确认收号',
  pending_owner_return_confirm: '待号主确认结账',
  pending_owner_checkout: '待号主确认结账',
  pending_renter_checkout: '待租客确认修正',
  checkout_disputed: '结账争议中',
  returned: '已归还',
  cancelled: '已取消',
  owner_timeout: '号主交接超时',
  renter_confirm_timeout: '租客确认超时',
  return_overdue: '归还逾期',
  owner_return_confirm_timeout: '号主确认结账超时',
  owner_checkout_confirm_timeout: '号主确认结账超时',
  admin_closed: '客服关闭',
  admin_abnormal: '客服标记异常',
  arbitrated: '已仲裁',
}

const settlementStatusMap: Record<SettlementStatus, string> = {
  unsettled: '未结算',
  pending: '待结算',
  frozen: '冻结中',
  settled: '已结算',
  refunded: '已退款',
  cancelled: '已取消',
  closed: '已关闭',
  disputed: '争议中',
  arbitrated: '已仲裁',
}

const realnameStatusMap: Partial<Record<RealnameStatusValue, string>> = {
  unverified: '未认证',
  pending: '认证中',
  verified: '已认证',
  rejected: '认证失败',
}

const userStatusMap: Record<UserStatus, string> = {
  active: '正常',
  frozen: '已冻结',
  disabled: '已禁用',
}

const riskStatusMap: Record<RiskStatus, string> = {
  normal: '正常',
  watch: '观察',
  restricted: '受限',
  blocked: '已拦截',
}

const disputeStatusMap: Record<DisputeStatus, string> = {
  open: '待处理',
  processing: '处理中',
  resolved: '已处理',
  closed: '已关闭',
}

const walletStatusMap: Record<WalletStatus, string> = {
  active: '正常',
  frozen: '已冻结',
  disabled: '已禁用',
}

const ledgerDirectionMap: Record<LedgerDirection, string> = {
  in: '收入',
  out: '支出',
  freeze: '冻结',
  unfreeze: '解冻',
}

const balanceTypeMap: Record<BalanceType, string> = {
  available: '可用余额',
  frozen: '冻结余额',
}

function readLabel(map: Record<string, string>, value: string) {
  return map[value] || value || '-'
}

export function listingStatusLabel(status: string) {
  return readLabel(listingStatusMap, status)
}

export function listingReviewStatusLabel(status: string) {
  return readLabel(listingReviewStatusMap, status)
}

export function orderStatusLabel(status: string) {
  return readLabel(orderStatusMap, status)
}

export function handoffStatusLabel(status: string) {
  return readLabel(handoffStatusMap, status)
}

export function settlementStatusLabel(status: string) {
  return readLabel(settlementStatusMap, status)
}

export function realnameStatusLabel(status: string) {
  return readLabel(realnameStatusMap, status)
}

export function userStatusLabel(status: string) {
  return readLabel(userStatusMap, status)
}

export function riskStatusLabel(status: string) {
  return readLabel(riskStatusMap, status)
}

export function disputeStatusLabel(status: string) {
  return readLabel(disputeStatusMap, status)
}

export function walletStatusLabel(status: string) {
  return readLabel(walletStatusMap, status)
}

export function ledgerDirectionLabel(direction: string) {
  return readLabel(ledgerDirectionMap, direction)
}

export function balanceTypeLabel(type: string) {
  return readLabel(balanceTypeMap, type)
}
