import axios from 'axios';
import { API_URL_USER } from '@/shared/api/api-url-user';
import { resultify } from '@/shared/lib/resultify';
import { CBDCAxiosError } from '@/shared/@types/error';
import { 
  UserFindAuthMethodParams,
  UserFindAuthMethodResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const userFindAuthMethod = (params: UserFindAuthMethodParams) => {
  return resultify(
    axios.post<UserFindAuthMethodResponse>(API_URL_USER.findAuthMethod(), params),
  );
};

export const useUserFindAuthMethodMutation = (options?: UseMutationOptions<UserFindAuthMethodResponse, CBDCAxiosError, UserFindAuthMethodParams>) => {
  const mutation = useMutation<UserFindAuthMethodResponse, CBDCAxiosError, UserFindAuthMethodParams>({
    ...options,
    mutationFn: (params: UserFindAuthMethodParams) => userFindAuthMethod(params),
  });

  return {
    ...mutation,
  };
};
