import client from './client' import type { Game, GameStatus, GameType, ProofType, Challenge, ChallengePreview, ChallengesPreviewResponse, AvailableGamesCount } from '@/types' export interface CreateGameData { title: string download_url: string genre?: string cover_url?: string // Game type fields game_type?: GameType playthrough_points?: number playthrough_description?: string playthrough_proof_type?: ProofType playthrough_proof_hint?: string } export interface UpdateGameData { title?: string download_url?: string genre?: string game_type?: GameType playthrough_points?: number playthrough_description?: string playthrough_proof_type?: ProofType playthrough_proof_hint?: string } export interface CreateChallengeData { title: string description: string type: string difficulty: string points: number estimated_time?: number proof_type: string proof_hint?: string } export const gamesApi = { list: async (marathonId: number, status?: GameStatus): Promise => { const params = status ? { status } : {} const response = await client.get(`/marathons/${marathonId}/games`, { params }) return response.data }, listPending: async (marathonId: number): Promise => { const response = await client.get(`/marathons/${marathonId}/games/pending`) return response.data }, get: async (id: number): Promise => { const response = await client.get(`/games/${id}`) return response.data }, create: async (marathonId: number, data: CreateGameData): Promise => { const response = await client.post(`/marathons/${marathonId}/games`, data) return response.data }, delete: async (id: number): Promise => { await client.delete(`/games/${id}`) }, update: async (id: number, data: UpdateGameData): Promise => { const response = await client.patch(`/games/${id}`, data) return response.data }, getAvailableGamesCount: async (marathonId: number): Promise => { const response = await client.get(`/marathons/${marathonId}/available-games-count`) return response.data }, getAvailableGames: async (marathonId: number): Promise => { const response = await client.get(`/marathons/${marathonId}/available-games`) return response.data }, approve: async (id: number): Promise => { const response = await client.post(`/games/${id}/approve`) return response.data }, reject: async (id: number): Promise => { const response = await client.post(`/games/${id}/reject`) return response.data }, uploadCover: async (id: number, file: File): Promise => { const formData = new FormData() formData.append('file', file) const response = await client.post(`/games/${id}/cover`, formData, { headers: { 'Content-Type': 'multipart/form-data' }, }) return response.data }, // Challenges getChallenges: async (gameId: number): Promise => { const response = await client.get(`/games/${gameId}/challenges`) return response.data }, createChallenge: async (gameId: number, data: CreateChallengeData): Promise => { const response = await client.post(`/games/${gameId}/challenges`, data) return response.data }, deleteChallenge: async (id: number): Promise => { await client.delete(`/challenges/${id}`) }, updateChallenge: async (id: number, data: Partial): Promise => { const response = await client.patch(`/challenges/${id}`, data) return response.data }, previewChallenges: async (marathonId: number, gameIds?: number[]): Promise => { const data = gameIds?.length ? { game_ids: gameIds } : undefined const response = await client.post(`/marathons/${marathonId}/preview-challenges`, data) return response.data }, saveChallenges: async (marathonId: number, challenges: ChallengePreview[]): Promise<{ message: string }> => { const response = await client.post<{ message: string }>(`/marathons/${marathonId}/save-challenges`, { challenges }) return response.data }, // Proposed challenges proposeChallenge: async (gameId: number, data: CreateChallengeData): Promise => { const response = await client.post(`/games/${gameId}/propose-challenge`, data) return response.data }, getProposedChallenges: async (marathonId: number): Promise => { const response = await client.get(`/marathons/${marathonId}/proposed-challenges`) return response.data }, getMyProposedChallenges: async (marathonId: number): Promise => { const response = await client.get(`/marathons/${marathonId}/my-proposed-challenges`) return response.data }, approveChallenge: async (id: number): Promise => { const response = await client.patch(`/challenges/${id}/approve`) return response.data }, rejectChallenge: async (id: number): Promise => { const response = await client.patch(`/challenges/${id}/reject`) return response.data }, }