/**
 * Complete Onboarding Mutation
 *
 * Framework-agnostic mutation for completing onboarding.
 * Called from Server Actions.
 *
 * Pattern: Server Action → Mutation → Service → API Client
 */

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

export class CompleteOnboardingMutation implements Mutation<CompleteOnboardingInputDTO, CompleteOnboardingViewData, string> {
  async execute(params: CompleteOnboardingInputDTO): Promise<Result<CompleteOnboardingViewData, string>> {
    const onboardingService = new OnboardingService();
    const result = await onboardingService.completeOnboarding(params);
    
    if (result.isErr()) {
      return Result.err(mapToMutationError(result.getError()));
    }
    
    const output = CompleteOnboardingViewDataBuilder.build(result.unwrap());
    return Result.ok(output);
  }
}