import axios from 'axios';
import { API_URL } from '@/shared/api/urls';
import { resultify } from '@/shared/lib/resultify';
import { CBDCAxiosError } from '@/shared/@types/error';
import { 
  CashReceiptDetailParams,
  DetailResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const cashReceiptDetail = (params: CashReceiptDetailParams) => {
  return resultify(
    axios.post<DetailResponse>(API_URL.cashReceiptDetail(), params),
  );
};

export const useCashReceiptDetailMutation = (options?: UseMutationOptions<DetailResponse, CBDCAxiosError, CashReceiptDetailParams>) => {
  const mutation = useMutation<DetailResponse, CBDCAxiosError, CashReceiptDetailParams>({
    ...options,
    mutationFn: (params: CashReceiptDetailParams) => cashReceiptDetail(params),
  });

  return {
    ...mutation,
  };
};
