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 { 
  BillingListParams,
  BillingListResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const billingList = (params: BillingListParams) => {
  return resultify(
    axios.post<BillingListResponse>(API_URL_TRANSACTION.billingList(), params),
  );
};

export const useBillingListMutation = (options?: UseMutationOptions<BillingListResponse, CBDCAxiosError, BillingListParams>) => {
  const mutation = useMutation<BillingListResponse, CBDCAxiosError, BillingListParams>({
    ...options,
    mutationFn: (params: BillingListParams) => billingList(params),
  });

  return {
    ...mutation,
  };
};
