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

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

export const useVatReturnTaxInvoiceMutation = (options?: UseMutationOptions<VatReturnTaxInvoiceResponse, NiceAxiosError, VatReturnTaxInvoiceParams>) => {
  const mutation = useMutation<VatReturnTaxInvoiceResponse, NiceAxiosError, VatReturnTaxInvoiceParams>({
    ...options,
    mutationFn: (params: VatReturnTaxInvoiceParams) => vatReturnTaxInvoice(params),
  });

  return {
    ...mutation,
  };
};
