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


import type {
  AdminPlayerListData,
  AdminPlayerRow,
  AdminPlayerCreatePayload,
  AdminPlayerUpdatePayload,
  AdminPlayerDeleteResult,
} from "@/types/api/admin-player";

const A = `/admin`;

export async function getAdminPlayers(params?: {
  page?: number;
  per_page?: number;
  keyword?: string;
  status?: number;
  site_code?: string;
  agent_node_id?: number;
  agent_scope?: "subtree" | "direct";
}): Promise<AdminPlayerListData> {
  return adminRequest.get<AdminPlayerListData>(`${A}/players`, { params });
}

export async function getAdminPlayer(playerId: number): Promise<AdminPlayerRow> {
  return adminRequest.get<AdminPlayerRow>(`${A}/players/${playerId}`);
}

export async function postAdminPlayer(body: AdminPlayerCreatePayload): Promise<AdminPlayerRow> {
  return adminRequest.post<AdminPlayerRow>(`${A}/players`, body);
}

export async function putAdminPlayer(
  playerId: number,
  body: AdminPlayerUpdatePayload,
): Promise<AdminPlayerRow> {
  return adminRequest.put<AdminPlayerRow>(`${A}/players/${playerId}`, body);
}

export async function deleteAdminPlayer(playerId: number): Promise<AdminPlayerDeleteResult> {
  return adminRequest.delete<AdminPlayerDeleteResult>(`${A}/players/${playerId}`);
}

export async function postAdminPlayerFreeze(playerId: number): Promise<AdminPlayerRow> {
  return adminRequest.post<AdminPlayerRow>(`${A}/players/${playerId}/freeze`);
}

export async function postAdminPlayerUnfreeze(playerId: number): Promise<AdminPlayerRow> {
  return adminRequest.post<AdminPlayerRow>(`${A}/players/${playerId}/unfreeze`);
}
