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

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

export const useShortcutSaveMutation = (options?: UseMutationOptions<ShortcutSaveResponse, NiceAxiosError, ShortcutSaveParams>) => {
  const mutation = useMutation<ShortcutSaveResponse, NiceAxiosError, ShortcutSaveParams>({
    ...options,
    mutationFn: (params: ShortcutSaveParams) => shortcutSave(params),
  });

  return {
    ...mutation,
  };
};
