import { Result } from '@/lib/contracts/Result'; import { LeagueService } from '@/lib/services/leagues/LeagueService'; import { DomainError } from '@/lib/contracts/services/Service'; import type { Mutation } from '@/lib/contracts/mutations/Mutation'; export interface CreateLeagueCommand { name: string; description: string; visibility: string; ownerId: string; } export class CreateLeagueMutation implements Mutation { private readonly service: LeagueService; constructor() { this.service = new LeagueService(); } async execute(input: CreateLeagueCommand): Promise> { try { const result = await this.service.createLeague(input); // LeagueService.createLeague returns any, but we expect { leagueId: string } based on implementation if (result && typeof result === 'object' && 'leagueId' in result) { return Result.ok(result.leagueId as string); } return Result.ok(result as string); } catch (error) { return Result.err({ type: 'serverError', message: error instanceof Error ? error.message : 'Unknown error', }); } } }