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

export const cashReceiptList = (params: CashReceiptListParams) => {
  return resultify(
    axios.post<CashReceiptListResponse>(API_URL_TRANSACTION.cashReceiptList(), params),
  );
};

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

  return {
    ...mutation,
  };
};
