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

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

export const useVatReturnDetailMutation = (options?: UseMutationOptions<VatReturnDetailResponse, NiceAxiosError, VatReturnDetailParams>) => {
  const mutation = useMutation<VatReturnDetailResponse, NiceAxiosError, VatReturnDetailParams>({
    ...options,
    mutationFn: (params: VatReturnDetailParams) => vatReturnDetail(params),
  });

  return {
    ...mutation,
  };
};
