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

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

export const useExtensionArsApplyMutation = (options?: UseMutationOptions<ExtensionArsApplyResponse, NiceAxiosError, ExtensionArsApplyParams>) => {
  const mutation = useMutation<ExtensionArsApplyResponse, NiceAxiosError, ExtensionArsApplyParams>({
    ...options,
    mutationFn: (params: ExtensionArsApplyParams) => extensionArsApply(params),
  });

  return {
    ...mutation,
  };
};
