import axios from 'axios';
import { API_URL_VAT_RETURN } from '@/shared/api/api-url-vat-return';
import { resultify } from '@/shared/lib/resultify';
import { NiceAxiosError } from '@/shared/@types/error';
import { 
  VatReturnReferenceRequestResponse,
  VatReturnReferenceRequestParams,
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';
import { getHeaderUserAgent } from '@/shared/constants/url';

export const vatReturnReferenceRequest = (params: VatReturnReferenceRequestParams) => {
  let headerOptions = {
    menuId: 49,
    apiType: 'SELECT'
  };
  let options = {
    headers: {
      'X-User-Agent': getHeaderUserAgent(headerOptions)
    }
  };
  return resultify(
    axios.post<VatReturnReferenceRequestResponse>(API_URL_VAT_RETURN.vatReturnReferenceRequest(), params, options),
  );
};

export const useVatReturnReferenceRequestMutation = (options?: UseMutationOptions<VatReturnReferenceRequestResponse, NiceAxiosError, VatReturnReferenceRequestParams>) => {
  const mutation = useMutation<VatReturnReferenceRequestResponse, NiceAxiosError, VatReturnReferenceRequestParams>({
    ...options,
    mutationFn: (params: VatReturnReferenceRequestParams) => vatReturnReferenceRequest(params),
  });

  return {
    ...mutation,
  };
};
