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

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

export const useVatReturnBreakdownMutation = (options?: UseMutationOptions<VatReturnBreakdownResponse, NiceAxiosError, VatReturnBreakdownParams>) => {
  const mutation = useMutation<VatReturnBreakdownResponse, NiceAxiosError, VatReturnBreakdownParams>({
    ...options,
    mutationFn: (params: VatReturnBreakdownParams) => vatReturnBreakdown(params),
  });

  return {
    ...mutation,
  };
};
