import axios from 'axios';
import { API_URL_TRANSACTION } from '@/shared/api/api-url-transaction';
import { resultify } from '@/shared/lib/resultify';
import { NiceAxiosError } from '@/shared/@types/error';
import { 
  CashReceiptListParams,
  CashReceiptListResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';
import { getHeaderUserAgent } from '@/shared/constants/url';

export const cashReceiptList = (params: CashReceiptListParams) => {
  let headerOptions = {
    menuId: 32,
    apiType: 'SELECT'
  };
  let options = {
    headers: {
      'X-User-Agent': getHeaderUserAgent(headerOptions)
    }
  };
  return resultify(
    axios.post<CashReceiptListResponse>(API_URL_TRANSACTION.cashReceiptList(), params, options),
  );
};

export const useCashReceiptListMutation = (options?: UseMutationOptions<CashReceiptListResponse, NiceAxiosError, CashReceiptListParams>) => {
  const mutation = useMutation<CashReceiptListResponse, NiceAxiosError, CashReceiptListParams>({
    ...options,
    mutationFn: (params: CashReceiptListParams) => cashReceiptList(params),
  });

  return {
    ...mutation,
  };
};
