import { Result } from '@/lib/contracts/Result'; import { LeagueService } from '@/lib/services/leagues/LeagueService'; import type { Mutation } from '@/lib/contracts/mutations/Mutation'; export interface ScheduleAdminCommand { leagueId: string; seasonId: string; raceId?: string; input?: { track: string; car: string; scheduledAtIso: string }; } export class ScheduleAdminMutation implements Mutation { private readonly service: LeagueService; constructor() { this.service = new LeagueService(); } async execute(_command: ScheduleAdminCommand): Promise> { return Result.err('Use specific methods'); } async publishSchedule( leagueId: string, seasonId: string, ): Promise> { try { const result = await this.service.publishAdminSchedule(leagueId, seasonId); if (result.isErr()) { return Result.err('Failed to publish schedule'); } return Result.ok(undefined); } catch (error) { return Result.err('Failed to publish schedule'); } } async unpublishSchedule( leagueId: string, seasonId: string, ): Promise> { try { const result = await this.service.unpublishAdminSchedule(leagueId, seasonId); if (result.isErr()) { return Result.err('Failed to unpublish schedule'); } return Result.ok(undefined); } catch (error) { return Result.err('Failed to unpublish schedule'); } } async createRace( leagueId: string, seasonId: string, input: { track: string; car: string; scheduledAtIso: string }, ): Promise> { try { const result = await this.service.createAdminScheduleRace(leagueId, seasonId, input); if (result.isErr()) { return Result.err('Failed to create race'); } return Result.ok(undefined); } catch (error) { return Result.err('Failed to create race'); } } async updateRace( leagueId: string, seasonId: string, raceId: string, input: Partial<{ track: string; car: string; scheduledAtIso: string }>, ): Promise> { try { const result = await this.service.updateAdminScheduleRace(leagueId, seasonId, raceId, input); if (result.isErr()) { return Result.err('Failed to update race'); } return Result.ok(undefined); } catch (error) { return Result.err('Failed to update race'); } } async deleteRace( leagueId: string, seasonId: string, raceId: string, ): Promise> { try { const result = await this.service.deleteAdminScheduleRace(leagueId, seasonId, raceId); if (result.isErr()) { return Result.err('Failed to delete race'); } return Result.ok(undefined); } catch (error) { return Result.err('Failed to delete race'); } } }