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 { ExtensionAccountHolderSearchRequestParams, ExtensionAccountHolderSearchRequestResponse } from '../../model/account-holder-search/types';
import { getHeaderUserAgent } from '@/shared/constants/url';

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

export const useExtensionAccountHolderSearchRequestMutation = (options?: UseMutationOptions<ExtensionAccountHolderSearchRequestResponse, NiceAxiosError, ExtensionAccountHolderSearchRequestParams>) => {
  const mutation = useMutation<ExtensionAccountHolderSearchRequestResponse, NiceAxiosError, ExtensionAccountHolderSearchRequestParams>({
    ...options,
    mutationFn: (params: ExtensionAccountHolderSearchRequestParams) => extensionAccountHolderSearchRequest(params),
  });

  return {
    ...mutation,
  };
};