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

export const invoiceDetail = (params: InvoiceDetailParams) => {
  return resultify(
    axios.post<InvoiceDetailResponse>(API_URL.allTransactionList(), params),
  );
};

export const useInvoiceDetailMutation = (options?: UseMutationOptions<InvoiceDetailResponse, CBDCAxiosError, InvoiceDetailParams>) => {
  const mutation = useMutation<InvoiceDetailResponse, CBDCAxiosError, InvoiceDetailParams>({
    ...options,
    mutationFn: (params: InvoiceDetailParams) => invoiceDetail(params),
  });

  return {
    ...mutation,
  };
};
