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

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

export const useExtensionArsListMutation = (options?: UseMutationOptions<ExtensionArsListResponse, NiceAxiosError, ExtensionArsListParams>) => {
  const mutation = useMutation<ExtensionArsListResponse, NiceAxiosError, ExtensionArsListParams>({
    ...options,
    mutationFn: (params: ExtensionArsListParams) => extensionArsList(params),
  });

  return {
    ...mutation,
  };
};
