import type { AdminReportDailyProfitRow } from "@/types/api/admin-reports";

export type DashboardAnalyticsPeriod =
  | "today"
  | "last_7_days"
  | "last_30_days"
  | "this_month"
  | "lifetime"
  | "custom";

export type DashboardAnalyticsMetric = "overview" | "bet" | "payout" | "profit";

export type AdminDashboardAnalyticsSummary = {
  total_bet_minor: number;
  total_payout_minor: number;
  approx_house_gross_minor: number;
  draw_count: number;
  business_day_count: number;
};

export type AdminDashboardAnalyticsPlayRow = {
  play_code: string;
  dimension: number;
  total_bet_minor: number;
  total_payout_minor: number;
  approx_house_gross_minor: number;
};

export type AdminDashboardAnalyticsAgentRow = {
  agent_node_id: number;
  agent_code: string;
  agent_name: string;
  total_bet_minor: number;
  total_payout_minor: number;
  approx_house_gross_minor: number;
};

export type AdminDashboardAnalyticsChartMeta = {
  chart_date_from: string;
  chart_date_to: string;
  truncated: boolean;
  span_days: number;
};

/** `GET /api/v1/admin/dashboard/analytics` */
export type AdminDashboardAnalyticsData = {
  period: DashboardAnalyticsPeriod;
  metric: DashboardAnalyticsMetric;
  play_code: string | null;
  date_from: string;
  date_to: string;
  /** 绑定代理时为 share_profit（本级占成），平台账号为 house_gross */
  profit_scope?: "share_profit" | "house_gross";
  currency_code: string | null;
  summary: AdminDashboardAnalyticsSummary;
  daily_series: AdminReportDailyProfitRow[];
  chart_meta: AdminDashboardAnalyticsChartMeta;
  play_breakdown: AdminDashboardAnalyticsPlayRow[];
  agent_breakdown: AdminDashboardAnalyticsAgentRow[];
};

export type AdminDashboardAnalyticsQuery = {
  period?: DashboardAnalyticsPeriod;
  date_from?: string;
  date_to?: string;
  metric?: DashboardAnalyticsMetric;
  play_code?: string;
  site_code?: string;
  agent_node_id?: number;
};
