/** `POST /api/v1/ticket/preview` / `place` 请求行 */
export type TicketLineInput = {
  number: string;
  play_code: string;
  amount: number;
  digit_slot?: number;
  dimension?: "D2" | "D3" | "D4";
};

export type TicketConfigVersions = {
  play_config_version_no: number;
  odds_version_no: number;
  risk_cap_version_no: number;
};

export type TicketPreviewPayload = {
  draw_id: string;
  currency_code: string;
  client_trace_id?: string | null;
  lines: TicketLineInput[];
};

export type TicketPlacePayload = TicketPreviewPayload & {
  expected_config_versions?: TicketConfigVersions;
};

export type TicketPreviewLine = {
  client_line_no: number;
  number: string;
  play_code: string;
  normalized_number: string;
  combination_count: number;
  total_bet_amount: number;
  rebate_rate: string;
  rebate_amount: number;
  actual_deduct_amount: number;
  estimated_max_payout: number;
  risk_status: string;
  warnings: unknown[];
  rule_snapshot_json: unknown;
};

export type TicketPreviewWarning = {
  number_4d: string;
  message: string;
};

export type TicketPreviewData = {
  draw: { draw_id: string; status: string };
  config_versions: TicketConfigVersions;
  summary: {
    total_bet_amount: number;
    total_rebate_amount: number;
    total_actual_deduct: number;
    total_estimated_payout: number;
    instant_rebate_applied?: boolean;
  };
  lines: TicketPreviewLine[];
  warnings: TicketPreviewWarning[];
};

export type TicketPlaceItem = {
  ticket_no: string;
  play_code: string;
  number: string;
  total_bet_amount: number;
  actual_deduct_amount: number;
  estimated_max_payout: number;
  combination_count: number;
  status?: "success" | "failed" | string;
  fail_reason_code?: string | null;
  fail_reason_text?: string | null;
};

export type TicketPlaceData = {
  order_no: string;
  draw: { draw_id: string; status: string; db_status?: string };
  summary: TicketPreviewData["summary"] & {
    order_status?: string;
    success_count?: number;
    pending_confirm_count?: number;
    failure_count?: number;
  };
  balance_after: number;
  items: TicketPlaceItem[];
};
