/**
 * 系统账户划转类型定义
 * [2026-01-06] 新增
 */

// 划转订单状态
export type SystemWithdrawalStatus = 'PENDING' | 'FROZEN' | 'BROADCASTED' | 'CONFIRMED' | 'FAILED';

// 系统账户信息
// [2026-01-07] 修复：accountName 与后端返回字段对齐
export interface SystemAccount {
  accountSequence: string;
  accountName: string;  // 后端返回 accountName
  balance?: string;
}

// 划转订单
export interface SystemWithdrawalOrder {
  orderId: number;
  orderNo: string;
  fromAccountSequence: string;
  fromAccountName: string;
  toAccountSequence: string;
  toUserId: number;
  toUserName?: string;
  toAddress: string;
  amount: string;
  chainType: string;
  txHash?: string;
  status: SystemWithdrawalStatus;
  errorMessage?: string;
  operatorId: string;
  operatorName?: string;
  memo?: string;
  frozenAt?: string;
  broadcastedAt?: string;
  confirmedAt?: string;
  createdAt: string;
}

// 划转请求
export interface SystemWithdrawalRequest {
  fromAccountSequence: string;
  toAccountSequence: string;
  amount: string;
  memo?: string;
  operatorId: string;
  operatorName?: string;
}

// 划转响应
export interface SystemWithdrawalResponse {
  orderNo: string;
  status: SystemWithdrawalStatus;
  message: string;
}

// 订单查询参数
export interface SystemWithdrawalQueryParams {
  fromAccountSequence?: string;
  toAccountSequence?: string;
  status?: SystemWithdrawalStatus;
  page?: number;
  limit?: number;
}

// 订单列表响应
export interface SystemWithdrawalOrderListResponse {
  items: SystemWithdrawalOrder[];
  total: number;
  page: number;
  limit: number;
}

// 状态配置
export const SYSTEM_WITHDRAWAL_STATUS_CONFIG: Record<SystemWithdrawalStatus, { label: string; color: string }> = {
  PENDING: { label: '待处理', color: '#faad14' },
  FROZEN: { label: '已冻结', color: '#1890ff' },
  BROADCASTED: { label: '已广播', color: '#722ed1' },
  CONFIRMED: { label: '已确认', color: '#52c41a' },
  FAILED: { label: '失败', color: '#ff4d4f' },
};

// 获取状态信息
export function getSystemWithdrawalStatusInfo(status: SystemWithdrawalStatus) {
  return SYSTEM_WITHDRAWAL_STATUS_CONFIG[status] || { label: status, color: '#999' };
}
