import axios from 'axios';
import { API_URL_USER } from '@/shared/api/api-url-user';
import { resultify } from '@/shared/lib/resultify';
import { NiceAxiosError } from '@/shared/@types/error';
import { 
  UserExistsUseridResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';
import { getHeaderUserAgent } from '@/shared/constants/url';

export const userExistsUserid = (usrId: string) => {
  let headerOptions = {
    menuId: 45,
    apiType: 'SELECT'
  };
  let options = {
    headers: {
      'X-User-Agent': getHeaderUserAgent(headerOptions)
    }
  };
  return resultify(
    axios.post<UserExistsUseridResponse>(API_URL_USER.userExistsUserid(usrId)),
  );
};

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

  return {
    ...mutation,
  };
};
