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

export const billingCharge = (params: BillingChargeParams) => {
  return resultify(
    axios.post<BillingChargeResponse>(API_URL.billingDetail(), params),
  );
};

export const useBillingChargeMutation = (options?: UseMutationOptions<BillingChargeResponse, CBDCAxiosError, BillingChargeParams>) => {
  const mutation = useMutation<BillingChargeResponse, CBDCAxiosError, BillingChargeParams>({
    ...options,
    mutationFn: (params: BillingChargeParams) => billingCharge(params),
  });

  return {
    ...mutation,
  };
};
