import axios from 'axios';
import { API_URL_VAT_RETURN } from '@/shared/api/api-url-vat-return';
import { resultify } from '@/shared/lib/resultify';
import { CBDCAxiosError } from '@/shared/@types/error';
import { 
  VatReturnListResponse,
  VatReturnListParams,
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const vatReturnList = (params: VatReturnListParams) => {
  return resultify(
    axios.post<VatReturnListResponse>(API_URL_VAT_RETURN.vatReturnList(), params),
  );
};

export const useVatReturnListMutation = (options?: UseMutationOptions<VatReturnListResponse, CBDCAxiosError, VatReturnListParams>) => {
  const mutation = useMutation<VatReturnListResponse, CBDCAxiosError, VatReturnListParams>({
    ...options,
    mutationFn: (params: VatReturnListParams) => vatReturnList(params),
  });

  return {
    ...mutation,
  };
};
