import { Mutation } from '@/lib/contracts/mutations/Mutation';
import { Result } from '@/lib/contracts/Result';
import { mapToMutationError } from '@/lib/contracts/mutations/MutationError';
import { OnboardingService } from '@/lib/services/onboarding/OnboardingService';
import { RequestAvatarGenerationInputDTO } from '@/lib/types/generated/RequestAvatarGenerationInputDTO';
import { GenerateAvatarsViewDataBuilder } from '@/lib/builders/view-data/GenerateAvatarsViewDataBuilder';
import { GenerateAvatarsViewData } from '@/lib/builders/view-data/GenerateAvatarsViewData';

export class GenerateAvatarsMutation implements Mutation<RequestAvatarGenerationInputDTO, GenerateAvatarsViewData, string> {
  async execute(input: RequestAvatarGenerationInputDTO): Promise<Result<GenerateAvatarsViewData, string>> {
    const service = new OnboardingService();
    const result = await service.generateAvatars(input);
    
    if (result.isErr()) {
      return Result.err(mapToMutationError(result.getError()));
    }
    
    const output = GenerateAvatarsViewDataBuilder.build(result.unwrap());
    return Result.ok(output);
  }
}