/**
 * 财务相关类型定义
 */

// 结算单状态
export type SettlementStatus = 'pending' | 'approved' | 'rejected' | 'paid';

// 提现状态
export type WithdrawalStatus = 'pending' | 'approved' | 'rejected' | 'completed' | 'failed';

// 交易类型
export type TransactionType =
  | 'order_income'        // 订单收入
  | 'settlement_freeze'   // 结算冻结
  | 'settlement_income'   // 结算收入
  | 'withdrawal_freeze'   // 提现冻结
  | 'withdrawal_expense'  // 提现支出
  | 'withdrawal_refund'   // 提现退回
  | 'refund_expense'      // 退款支出
  | 'cashback_income'     // 返现收入
  | 'service_fee';        // 服务费

// 结算单接口
export interface Settlement {
  id: number;
  merchantId: number;
  periodStart: string;
  periodEnd: string;
  totalAmount: number;
  serviceFee: number;
  actualAmount: number;
  status: SettlementStatus;
  orderCount: number;
  approvedAt?: string;
  approvedBy?: number;
  rejectedAt?: string;
  rejectedBy?: number;
  rejectReason?: string;
  paidAt?: string;
  createdAt: string;
  updatedAt: string;
}

// 提现记录接口
export interface Withdrawal {
  id: number;
  userId?: number;
  merchantId?: number;
  amount: number;
  fee: number;
  actualAmount: number;
  status: WithdrawalStatus;
  bankName?: string;
  bankAccount?: string;
  accountName?: string;
  approvedAt?: string;
  approvedBy?: number;
  rejectedAt?: string;
  rejectedBy?: number;
  rejectReason?: string;
  completedAt?: string;
  transactionId?: string;
  createdAt: string;
  updatedAt: string;
}

// 交易记录接口
export interface Transaction {
  id: number;
  userId?: number;
  merchantId?: number;
  type: TransactionType;
  amount: number;
  balance: number;
  orderId?: number;
  settlementId?: number;
  withdrawalId?: number;
  description: string;
  createdAt: string;
}

// 账户信息接口
export interface Account {
  balance: number;
  frozenAmount: number;
  availableAmount: number;
  totalIncome: number;
  totalExpense: number;
}

// 统计数据接口
export interface FinanceStatistics {
  todayIncome: number;
  todayOrders: number;
  monthIncome: number;
  monthOrders: number;
  totalIncome: number;
  totalOrders: number;
  pendingSettlements: number;
  pendingWithdrawals: number;
}

// 分页查询参数
export interface FinanceQueryParams {
  page?: number;
  pageSize?: number;
  status?: string;
  startDate?: string;
  endDate?: string;
  keyword?: string;
}

// 分页响应
export interface PaginatedResponse<T> {
  list: T[];
  total: number;
  page: number;
  pageSize: number;
  totalPages: number;
}

// 审核操作参数
export interface ApprovalParams {
  id: number;
  action: 'approve' | 'reject';
  rejectReason?: string;
}
