import { API_URL } from "@/config"; import type { Tournament } from "@michess/types"; export const fetchTournaments = async (): Promise => { const res = await fetch(`${API_URL}/v1/tournaments`, { cache: "no-store" }); if (!res.ok) return []; return res.json(); }; export const fetchTournament = async (code: string): Promise => { const res = await fetch(`${API_URL}/v1/tournaments/${code}`, { cache: "no-store" }); if (!res.ok) return null; return res.json(); }; export const createTournament = async (name: string, timeControl?: number, maxPlayers?: number): Promise => { const res = await fetch(`${API_URL}/v1/tournaments`, { method: "POST", credentials: "include", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ name, timeControl, maxPlayers }) }); if (!res.ok) return null; return res.json(); }; export const joinTournament = async (code: string): Promise => { const res = await fetch(`${API_URL}/v1/tournaments/${code}/join`, { method: "POST", credentials: "include" }); if (!res.ok) return null; return res.json(); }; export const startTournament = async (code: string): Promise => { const res = await fetch(`${API_URL}/v1/tournaments/${code}/start`, { method: "POST", credentials: "include" }); if (!res.ok) return null; return res.json(); };