import axios from 'axios';
import { API_URL_ADDITIONAL_SERVICE } from '@/shared/api/api-url-additional-service';
import { resultify } from '@/shared/lib/resultify';
import { NiceAxiosError } from '@/shared/@types/error';

import {
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';
import { ExtensionKeyinApplyParams, ExtensionKeyinApplyResponse } from '../model/key-in/types';
import { getHeaderUserAgent } from '@/shared/constants/url';

export const extensionKeyinApply = (params: ExtensionKeyinApplyParams) => {
  let headerOptions = {
    menuId: 56,
    apiType: 'INSERT'
  };
  let options = {
    headers: {
      'X-User-Agent': getHeaderUserAgent(headerOptions)
    }
  };
  return resultify(
    axios.post<ExtensionKeyinApplyResponse>(API_URL_ADDITIONAL_SERVICE.extensionKeyinApply(), params, options),
  );
};

export const useExtensionKeyinApplyMutation = (options?: UseMutationOptions<ExtensionKeyinApplyResponse, NiceAxiosError, ExtensionKeyinApplyParams>) => {
  const mutation = useMutation<ExtensionKeyinApplyResponse, NiceAxiosError, ExtensionKeyinApplyParams>({
    ...options,
    mutationFn: (params: ExtensionKeyinApplyParams) => extensionKeyinApply(params),
  });

  return {
    ...mutation,
  };
};
