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 { 
  UserFindAuthMethodParams,
  UserFindAuthMethodResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';
import { getHeaderUserAgent } from '@/shared/constants/url';

export const userFindAuthMethod = (params: UserFindAuthMethodParams) => {
  let headerOptions = {
    menuId: 45,
    apiType: 'SELECT'
  };
  let options = {
    headers: {
      'X-User-Agent': getHeaderUserAgent(headerOptions)
    }
  };
  return resultify(
    axios.post<UserFindAuthMethodResponse>(API_URL_USER.findAuthMethod(), params, options),
  );
};

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

  return {
    ...mutation,
  };
};
