import client from './client' import type { Marathon, MarathonListItem, LeaderboardEntry, ParticipantWithUser, ParticipantRole, GameProposalMode } from '@/types' export interface CreateMarathonData { title: string description?: string start_date: string duration_days?: number is_public?: boolean game_proposal_mode?: GameProposalMode } export const marathonsApi = { list: async (): Promise => { const response = await client.get('/marathons') return response.data }, get: async (id: number): Promise => { const response = await client.get(`/marathons/${id}`) return response.data }, create: async (data: CreateMarathonData): Promise => { const response = await client.post('/marathons', data) return response.data }, update: async (id: number, data: Partial): Promise => { const response = await client.patch(`/marathons/${id}`, data) return response.data }, delete: async (id: number): Promise => { await client.delete(`/marathons/${id}`) }, start: async (id: number): Promise => { const response = await client.post(`/marathons/${id}/start`) return response.data }, finish: async (id: number): Promise => { const response = await client.post(`/marathons/${id}/finish`) return response.data }, join: async (inviteCode: string): Promise => { const response = await client.post('/marathons/join', { invite_code: inviteCode }) return response.data }, joinPublic: async (id: number): Promise => { const response = await client.post(`/marathons/${id}/join`) return response.data }, getParticipants: async (id: number): Promise => { const response = await client.get(`/marathons/${id}/participants`) return response.data }, setParticipantRole: async (marathonId: number, userId: number, role: ParticipantRole): Promise => { const response = await client.patch( `/marathons/${marathonId}/participants/${userId}/role`, { role } ) return response.data }, getLeaderboard: async (id: number): Promise => { const response = await client.get(`/marathons/${id}/leaderboard`) return response.data }, }