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

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

export const useShortcutDefaultMutation = (options?: UseMutationOptions<ShortcutDefaultResponse, NiceAxiosError, ShortcutDefaultParams>) => {
  const mutation = useMutation<ShortcutDefaultResponse, NiceAxiosError, ShortcutDefaultParams>({
    ...options,
    mutationFn: (params: ShortcutDefaultParams) => shortcutDefault(params),
  });

  return {
    ...mutation,
  };
};
