import axios from 'axios';
import { API_URL_ADDITIONAL_SERVICE } from '@/shared/api/api-url-additional-service';
import { resultify } from '@/shared/lib/resultify';
import { CBDCAxiosError } from '@/shared/@types/error';
import { ExtensionAccountHolderSearchRequestParams, ExtensionAccountHolderSearchRequestResponse } from '../../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const extensionAccountHolderSearchRequest = (params: ExtensionAccountHolderSearchRequestParams) => {
  return resultify(
    axios.post<ExtensionAccountHolderSearchRequestResponse>(API_URL_ADDITIONAL_SERVICE.extensionAccountHolderSearchRequest(), params),
  );
};

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

  return {
    ...mutation,
  };
};