import { LeaguesApiClient } from "@/lib/api/leagues/LeaguesApiClient"; import { DriversApiClient } from "@/lib/api/drivers/DriversApiClient"; import { SponsorsApiClient } from "@/lib/api/sponsors/SponsorsApiClient"; import { RacesApiClient } from "@/lib/api/races/RacesApiClient"; import { CreateLeagueInputDTO } from "@/lib/types/generated/CreateLeagueInputDTO"; import { CreateLeagueOutputDTO } from "@/lib/types/generated/CreateLeagueOutputDTO"; import type { MembershipRole } from "@/lib/types/MembershipRole"; import type { LeagueRosterJoinRequestDTO } from "@/lib/types/generated/LeagueRosterJoinRequestDTO"; import type { RaceDTO } from "@/lib/types/generated/RaceDTO"; import type { TotalLeaguesDTO } from '@/lib/types/generated/TotalLeaguesDTO'; import type { LeagueScoringConfigDTO } from "@/lib/types/generated/LeagueScoringConfigDTO"; import type { LeagueMembership } from "@/lib/types/LeagueMembership"; import type { LeagueSeasonSummaryDTO } from '@/lib/types/generated/LeagueSeasonSummaryDTO'; import type { LeagueScheduleDTO } from '@/lib/types/generated/LeagueScheduleDTO'; import type { CreateLeagueScheduleRaceInputDTO } from '@/lib/types/generated/CreateLeagueScheduleRaceInputDTO'; import type { CreateLeagueScheduleRaceOutputDTO } from '@/lib/types/generated/CreateLeagueScheduleRaceOutputDTO'; import type { UpdateLeagueScheduleRaceInputDTO } from '@/lib/types/generated/UpdateLeagueScheduleRaceInputDTO'; import type { LeagueScheduleRaceMutationSuccessDTO } from '@/lib/types/generated/LeagueScheduleRaceMutationSuccessDTO'; import type { LeagueSeasonSchedulePublishOutputDTO } from '@/lib/types/generated/LeagueSeasonSchedulePublishOutputDTO'; import type { LeagueRosterMemberDTO } from '@/lib/types/generated/LeagueRosterMemberDTO'; import type { LeagueMembershipsDTO } from '@/lib/types/generated/LeagueMembershipsDTO'; /** * League Service - DTO Only * * Returns raw API DTOs. No ViewModels or UX logic. * All client-side presentation logic must be handled by hooks/components. */ export class LeagueService { constructor( private readonly apiClient: LeaguesApiClient, private readonly driversApiClient?: DriversApiClient, private readonly sponsorsApiClient?: SponsorsApiClient, private readonly racesApiClient?: RacesApiClient ) {} async getAllLeagues(): Promise { return this.apiClient.getAllWithCapacityAndScoring(); } async getLeagueStandings(leagueId: string): Promise { return this.apiClient.getStandings(leagueId); } async getLeagueStats(): Promise { return this.apiClient.getTotal(); } async getLeagueSchedule(leagueId: string): Promise { return this.apiClient.getSchedule(leagueId); } async getLeagueSeasons(leagueId: string): Promise { return this.apiClient.getSeasons(leagueId); } async getLeagueSeasonSummaries(leagueId: string): Promise { return this.apiClient.getSeasons(leagueId); } async getAdminSchedule(leagueId: string, seasonId: string): Promise { return this.apiClient.getSchedule(leagueId, seasonId); } async publishAdminSchedule(leagueId: string, seasonId: string): Promise { return this.apiClient.publishSeasonSchedule(leagueId, seasonId); } async unpublishAdminSchedule(leagueId: string, seasonId: string): Promise { return this.apiClient.unpublishSeasonSchedule(leagueId, seasonId); } async createAdminScheduleRace( leagueId: string, seasonId: string, input: { track: string; car: string; scheduledAtIso: string }, ): Promise { const payload: CreateLeagueScheduleRaceInputDTO = { ...input, example: '' }; return this.apiClient.createSeasonScheduleRace(leagueId, seasonId, payload); } async updateAdminScheduleRace( leagueId: string, seasonId: string, raceId: string, input: Partial<{ track: string; car: string; scheduledAtIso: string }>, ): Promise { const payload: UpdateLeagueScheduleRaceInputDTO = { ...input, example: '' }; return this.apiClient.updateSeasonScheduleRace(leagueId, seasonId, raceId, payload); } async deleteAdminScheduleRace(leagueId: string, seasonId: string, raceId: string): Promise { return this.apiClient.deleteSeasonScheduleRace(leagueId, seasonId, raceId); } async getLeagueScheduleDto(leagueId: string, seasonId: string): Promise { return this.apiClient.getSchedule(leagueId, seasonId); } async publishLeagueSeasonSchedule(leagueId: string, seasonId: string): Promise { return this.apiClient.publishSeasonSchedule(leagueId, seasonId); } async unpublishLeagueSeasonSchedule(leagueId: string, seasonId: string): Promise { return this.apiClient.unpublishSeasonSchedule(leagueId, seasonId); } async createLeagueSeasonScheduleRace( leagueId: string, seasonId: string, input: CreateLeagueScheduleRaceInputDTO, ): Promise { return this.apiClient.createSeasonScheduleRace(leagueId, seasonId, input); } async updateLeagueSeasonScheduleRace( leagueId: string, seasonId: string, raceId: string, input: UpdateLeagueScheduleRaceInputDTO, ): Promise { return this.apiClient.updateSeasonScheduleRace(leagueId, seasonId, raceId, input); } async deleteLeagueSeasonScheduleRace( leagueId: string, seasonId: string, raceId: string, ): Promise { return this.apiClient.deleteSeasonScheduleRace(leagueId, seasonId, raceId); } async getLeagueMemberships(leagueId: string): Promise { return this.apiClient.getMemberships(leagueId); } async createLeague(input: CreateLeagueInputDTO): Promise { return this.apiClient.create(input); } async removeMember(leagueId: string, targetDriverId: string): Promise<{ success: boolean }> { const dto = await this.apiClient.removeRosterMember(leagueId, targetDriverId); return { success: dto.success }; } async updateMemberRole(leagueId: string, targetDriverId: string, newRole: MembershipRole): Promise<{ success: boolean }> { const dto = await this.apiClient.updateRosterMemberRole(leagueId, targetDriverId, newRole); return { success: dto.success }; } async getAdminRosterMembers(leagueId: string): Promise { return this.apiClient.getAdminRosterMembers(leagueId); } async getAdminRosterJoinRequests(leagueId: string): Promise { return this.apiClient.getAdminRosterJoinRequests(leagueId); } async approveJoinRequest(leagueId: string, joinRequestId: string): Promise<{ success: boolean }> { const dto = await this.apiClient.approveRosterJoinRequest(leagueId, joinRequestId); return { success: dto.success }; } async rejectJoinRequest(leagueId: string, joinRequestId: string): Promise<{ success: boolean }> { const dto = await this.apiClient.rejectRosterJoinRequest(leagueId, joinRequestId); return { success: dto.success }; } async getLeagueDetail(leagueId: string): Promise { return this.apiClient.getAllWithCapacityAndScoring(); } async getLeagueDetailPageData(leagueId: string): Promise { return this.apiClient.getAllWithCapacityAndScoring(); } async getScoringPresets(): Promise { const result = await this.apiClient.getScoringPresets(); return result.presets; } }