import { isApiError } from "@/lib/errors" import type { Player } from "@/lib/types" import { httpJson } from "./http" type Paginated = { items: T[] | null meta: { total: number offset: number limit: number } } export async function listPlayers(): Promise { const res = await httpJson>("/api/v1/players?offset=0&limit=100", { cache: "no-store", }) return res.items ?? [] } export async function getPlayerById(playerId: string): Promise { try { return await httpJson(`/api/v1/players/${encodeURIComponent(playerId)}`, { cache: "no-store", }) } catch (error) { if (error instanceof Error && error.message === "UNAUTHORIZED") { throw error } if (isApiError(error) && error.code === 404) { return undefined } throw error } } export async function listPlayersByShop(shopId: string): Promise { const players = await listPlayers() return players.filter((player) => String(player.shopId) === shopId) }