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

export const shortcutUser = (params: ShortcutUserParams) => {
  let headerOptions = {
    menuId: 0,
    apiType: 'SELECT'
  };
  let options = {
    headers: {
      'X-User-Agent': getHeaderUserAgent(headerOptions)
    }
  };
  return resultify(
    axios.post<ShortcutUserResponse>(API_URL_USER.shortcutUser(), params, options),
  );
};

export const useShortcutUserMutation = (options?: UseMutationOptions<ShortcutUserResponse, NiceAxiosError, ShortcutUserParams>) => {
  const mutation = useMutation<ShortcutUserResponse, NiceAxiosError, ShortcutUserParams>({
    ...options,
    mutationFn: (params: ShortcutUserParams) => shortcutUser(params),
  });

  return {
    ...mutation,
  };
};
