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 { 
  UserModifyAuthMethodParams,
  UserModifyAuthMethodResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const userModifyAuthMethod = (params: UserModifyAuthMethodParams) => {
  return resultify(
    axios.post<UserModifyAuthMethodResponse>(API_URL_USER.modifyAuthMethod(), params),
  );
};

export const useUserModifyAuthMethodMutation = (options?: UseMutationOptions<UserModifyAuthMethodResponse, CBDCAxiosError, UserModifyAuthMethodParams>) => {
  const mutation = useMutation<UserModifyAuthMethodResponse, CBDCAxiosError, UserModifyAuthMethodParams>({
    ...options,
    mutationFn: (params: UserModifyAuthMethodParams) => userModifyAuthMethod(params),
  });

  return {
    ...mutation,
  };
};
