/** `GET /api/v1/wallet/logs` 单条流水 */
export type WalletLogItem = {
  log_id: string;
  type: string;
  biz_type: string;
  /** wallet_txn | credit_ledger */
  ledger_source?: string;
  funding_mode?: string;
  auth_source?: string | null;
  /** 正数为加款，负数为扣款（最小货币单位） */
  amount: number;
  amount_abs: number;
  direction: "in" | "out";
  currency_code: string;
  balance_after: number | null;
  /** 信用盘：false 表示账期收付记账，不改变可用信用 */
  affects_available_credit?: boolean;
  ref_id: string | null;
  idempotent_key: string | null;
  external_ref_no: string | null;
  status: string;
  remark: string | null;
  created_at: string | null;
};

/** 待对账划转（主站超时等，PRD §6.2 / §6.7） */
export type WalletPendingTransfer = {
  transfer_no: string;
  direction: string;
  type: string;
  currency_code: string;
  amount: number;
  status: string;
  fail_reason: string | null;
  idempotent_key: string;
  created_at: string | null;
};

export type WalletLogsData = {
  items: WalletLogItem[];
  total: number;
  page: number;
  per_page: number;
  /** 本页数据来源：钱包流水表 / 信用流水表 */
  ledger_source?: string;
  funding_mode?: string;
  auth_source?: string | null;
  pending_reconcile: WalletPendingTransfer[];
};

export function getWalletLogsLastPage(logs: Pick<WalletLogsData, "total" | "per_page"> | null): number {
  if (!logs || logs.per_page <= 0) return 1;
  return Math.max(1, Math.ceil(logs.total / logs.per_page));
}

export type GetWalletLogsParams = {
  page?: number;
  /** 每页条数（PRD 示例 `size`） */
  size?: number;
  /** 逗号分隔：transfer_in,transfer_out,bet,prize,refund,reversal */
  type?: string;
  /** 按钱包币种筛选 */
  currency?: string;
};
