export type RawSeasonParticipant = { id: { seasonId: number; personId: number }; person: { personId: number; name: string; birthDate: string; imageUrl: string | null; }; partner: unknown | null; }; export type RawSeason = { seasonId: number; show: number; seasonNumber: number; startDate?: string; endDate?: string | null; moderators: unknown[]; seasonParticipants: RawSeasonParticipant[]; }; export type SeasonParticipant = { id: number; name: string; birthYear?: number; imageUri: string; }; export type Season = { id: number; showId: number; seasonNumber: number; startDate?: string; endDate?: string | null; participants: SeasonParticipant[]; }; const SEASON_BASE_URL = "http://45.157.177.99:8080/shows"; export async function getSeason( showId: number, seasonNumber: number ): Promise { const url = `${SEASON_BASE_URL}/${showId}/seasons/${seasonNumber}`; try { console.log("[getSeason] Fetch:", url); const res = await fetch(url); console.log("[getSeason] Status:", res.status); if (res.status === 404) return null; if (!res.ok) throw new Error("Season fetch failed " + res.status); const raw: RawSeason = await res.json(); const participants: SeasonParticipant[] = raw.seasonParticipants.map( (p) => ({ id: p.person.personId, name: p.person.name, birthYear: p.person.birthDate ? Number(p.person.birthDate.slice(0, 4)) : undefined, imageUri: p.person.imageUrl ?? "https://via.placeholder.com/300x400.png?text=No+Image", }) ); return { id: raw.seasonId, showId: raw.show, seasonNumber: raw.seasonNumber, startDate: raw.startDate, endDate: raw.endDate, participants, }; } catch (e) { console.error("getSeason error:", e); throw e; } }