import axios from 'axios';
import { API_URL } from '@/shared/api/urls';
import { resultify } from '@/shared/lib/resultify';
import { CBDCAxiosError } from '@/shared/@types/error';
import { 
  UserExistsUseridParams,
  UserExistsUseridResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const userExistsUserid = (params: UserExistsUseridParams) => {
  return resultify(
    axios.post<UserExistsUseridResponse>(API_URL.userExistsUserid(), params),
  );
};

export const useUserExistsUseridMutation = (options?: UseMutationOptions<UserExistsUseridResponse, CBDCAxiosError, UserExistsUseridParams>) => {
  const mutation = useMutation<UserExistsUseridResponse, CBDCAxiosError, UserExistsUseridParams>({
    ...options,
    mutationFn: (params: UserExistsUseridParams) => userExistsUserid(params),
  });

  return {
    ...mutation,
  };
};
