import { adminRequest } from "@/lib/admin-http";

import { API_V1_PREFIX } from "./paths";

import type { AdminDashboardData } from "@/types/api/admin-dashboard";
import type {
  AdminDashboardAnalyticsData,
  AdminDashboardAnalyticsQuery,
} from "@/types/api/admin-dashboard-analytics";

const A = `${API_V1_PREFIX}/admin`;

/** 首页仪表盘聚合（大厅 + 当期财务/风控/异常转账等，按账号权限填充各块） */
export async function getAdminDashboard(): Promise<AdminDashboardData> {
  return adminRequest.get<AdminDashboardData>(`${A}/dashboard`);
}

/** 仪表盘可筛选分析（区间汇总、日趋势、玩法拆解） */
export async function getAdminDashboardAnalytics(
  query: AdminDashboardAnalyticsQuery = {},
): Promise<AdminDashboardAnalyticsData> {
  const params = new URLSearchParams();
  if (query.period) {
    params.set("period", query.period);
  }
  if (query.date_from) {
    params.set("date_from", query.date_from);
  }
  if (query.date_to) {
    params.set("date_to", query.date_to);
  }
  if (query.metric) {
    params.set("metric", query.metric);
  }
  if (query.play_code) {
    params.set("play_code", query.play_code);
  }
  const qs = params.toString();

  return adminRequest.get<AdminDashboardAnalyticsData>(
    `${A}/dashboard/analytics${qs ? `?${qs}` : ""}`,
  );
}
