import type { AdminDrawFinanceSummaryData } from "@/types/api/admin-draw-finance";
import type { AdminRiskPoolRow } from "@/types/api/admin-risk";
import type { DrawCurrentSnapshot } from "@/types/api/public-draw";

export type AdminDashboardWarning = {
  code: string;
  message: string;
};

export type AdminDashboardResolvedDraw = {
  id: number;
  draw_no: string;
};

export type AdminDashboardDrawPanel = {
  id: number;
  draw_no: string;
  business_date: string;
  sequence_no: number;
  status: string;
  hall_preview_status: string;
  result_batch_counts: {
    total: number;
    pending_review: number;
    published: number;
  };
};

export type AdminDashboardSoldOutBuckets = {
  d4: number;
  d3: number;
  d2: number;
  special: number;
  other: number;
};

export type AdminDashboardRiskSnapshot = {
  draw_id: number;
  draw_no: string;
  locked_amount: number;
  cap_amount: number;
  usage_percent: number;
  hot_pool_rows: AdminRiskPoolRow[];
  sold_out_buckets: AdminDashboardSoldOutBuckets;
};

export type AdminDashboardCapabilities = {
  draw_finance_risk: boolean;
  wallet_transfer_view: boolean;
};

/** 按业务日汇总的今日投注/派彩/盈亏（与报表 daily-profit 口径一致） */
export type AdminDashboardTodayFinance = {
  business_date: string;
  currency_code: string | null;
  total_bet_minor: number;
  total_payout_minor: number;
  approx_house_gross_minor: number;
};

/** 全平台历史累计投注/派彩/盈亏 */
export type AdminDashboardLifetimeFinance = {
  currency_code: string | null;
  total_bet_minor: number;
  total_payout_minor: number;
  approx_house_gross_minor: number;
  draw_count: number;
  business_day_count: number;
  date_from: string | null;
  date_to: string | null;
};

/** `GET /api/v1/admin/dashboard` */
export type AdminDashboardData = {
  hall: DrawCurrentSnapshot | null;
  resolved_draw: AdminDashboardResolvedDraw | null;
  today_finance: AdminDashboardTodayFinance | null;
  lifetime_finance: AdminDashboardLifetimeFinance | null;
  finance: AdminDrawFinanceSummaryData | null;
  draw: AdminDashboardDrawPanel | null;
  risk: AdminDashboardRiskSnapshot | null;
  abnormal_transfer_total: number | null;
  warnings: AdminDashboardWarning[];
  capabilities: AdminDashboardCapabilities;
};
