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

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

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

  return {
    ...mutation,
  };
};
