import { requestClient } from '#/api/request';

export interface CountryDashboardMetric {
  countryCode: string;
  countryName: string;
  countryNewUser: number;
  d1RetentionBaseUser: number;
  d1RetentionRate: number | string;
  d1RetentionUser: number;
  d7RetentionBaseUser: number;
  d7RetentionRate: number | string;
  d7RetentionUser: number;
  d30RetentionBaseUser: number;
  d30RetentionRate: number | string;
  d30RetentionUser: number;
  dailyActiveUser: number;
  dealerRecharge: number | string;
  googleRecharge: number | string;
  gamePayoutRate: number | string;
  gamePayout: number | string;
  gameProfit: number | string;
  gameProfitRate: number | string;
  gameTotalFlow: number | string;
  gameUser: number;
  giftConsume: number | string;
  luckyGiftAnchorShare: number | string;
  luckyGiftPayout: number | string;
  luckyGiftPayoutRate: number | string;
  luckyGiftProfit: number | string;
  luckyGiftProfitRate: number | string;
  luckyGiftTotalFlow: number | string;
  luckyGiftUser: number;
  luckyGiftUserRate: number | string;
  mifapayRecharge: number | string;
  newUserRecharge: number | string;
  officialRecharge: number | string;
  periodKey: string;
  periodName: string;
  salaryExchange: number | string;
  totalRecharge: number | string;
}

export interface CountryDashboardResult {
  computedAt: string;
  endDate?: string;
  periodType: string;
  records: CountryDashboardMetric[];
  startDate?: string;
  statTimezone?: string;
  total: CountryDashboardMetric;
}

export interface CountryDashboardRechargeDetail {
  amount: number | string;
  coinQuantity: number | string;
  countryCode: string;
  countryName: string;
  createTime: string;
  recordId: string;
  remark: string;
  sourceChannel: string;
  sourceType: string;
  userAccount: string;
  userId: number | string;
  userNickname: string;
}

export interface CountryDashboardGameMetric {
  consumeAmount: number | string;
  countryCode: string;
  countryName: string;
  gameId: string;
  gameName: string;
  gameProvider: string;
  orderCount: number;
  payoutAmount: number | string;
  payoutRate: number | string;
  periodKey: string;
  periodName: string;
  profitAmount: number | string;
  profitRate: number | string;
  refreshedAt: string;
  statTimezone: string;
  userCount: number;
}

export async function countryDashboard(params: Record<string, any> = {}) {
  return requestClient.get<CountryDashboardResult>('/datav/country-dashboard', {
    params,
  });
}

export async function countryDashboardRechargeDetails(
  params: Record<string, any> = {},
) {
  return requestClient.get<{
    current: number;
    records: CountryDashboardRechargeDetail[];
    size: number;
    total: number;
  }>('/datav/country-dashboard/recharge-details', {
    params,
  });
}

export async function countryDashboardGameMetrics(
  params: Record<string, any> = {},
) {
  return requestClient.get<{
    current: number;
    records: CountryDashboardGameMetric[];
    size: number;
    total: number;
  }>('/datav/country-dashboard/game-metrics', {
    params,
  });
}

export async function countryDashboardGameSummaries(
  params: Record<string, any> = {},
) {
  return requestClient.get<{
    current: number;
    records: CountryDashboardGameMetric[];
    size: number;
    total: number;
  }>('/datav/country-dashboard/game-metrics/games', {
    params,
  });
}

export async function countryDashboardGameCountryRank(
  params: Record<string, any> = {},
) {
  return requestClient.get<CountryDashboardGameMetric[]>(
    '/datav/country-dashboard/game-metrics/country-rank',
    {
      params,
    },
  );
}

export async function latestActiveUserCountryCode(params: Record<string, any> = {}) {
  return requestClient.get<Array<Record<string, any>>>(
    '/datav/active/user-country-code',
    {
      params,
    },
  );
}

export async function onlineUserCount(params: Record<string, any> = {}) {
  return requestClient.get<number>('/datav/online/user/count', {
    params,
  });
}

export async function onlineRoomCount(params: Record<string, any> = {}) {
  return requestClient.get<number>('/datav/online/room/count', {
    params,
  });
}
