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

export const userExistsUserid = (usrId: string) => {
  return resultify(
    axios.post<UserExistsUseridResponse>(API_URL_USER.userExistsUserid(usrId)),
  );
};

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

  return {
    ...mutation,
  };
};
