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

export const userModifyAuthMethod = (params: UserModifyAuthMethodParams) => {
  let headerOptions = {
    menuId: 45,
    apiType: 'UPDATE'
  };
  let options = {
    headers: {
      'X-User-Agent': getHeaderUserAgent(headerOptions)
    }
  };
  return resultify(
    axios.post<UserModifyAuthMethodResponse>(API_URL_USER.modifyAuthMethod(), params, options),
  );
};

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

  return {
    ...mutation,
  };
};
