'use client';

import { useMutation, UseMutationOptions } from '@tanstack/react-query';
import { useInject } from '@/lib/di/hooks/useInject';
import { DRIVER_SERVICE_TOKEN } from '@/lib/di/tokens';
import { ApiError } from '@/lib/api/base/ApiError';
import type { CompleteOnboardingInputDTO } from '@/lib/types/generated/CompleteOnboardingInputDTO';
import { CompleteOnboardingViewModel } from '@/lib/view-models/CompleteOnboardingViewModel';

export function useCreateDriver(
  options?: Omit<UseMutationOptions<CompleteOnboardingViewModel, ApiError, CompleteOnboardingInputDTO>, 'mutationFn'>
) {
  const driverService = useInject(DRIVER_SERVICE_TOKEN);

  return useMutation<CompleteOnboardingViewModel, ApiError, CompleteOnboardingInputDTO>({
    mutationFn: async (input) => {
      const dto = await driverService.completeDriverOnboarding(input);
      return new CompleteOnboardingViewModel(dto);
    },
    ...options,
  });
}