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

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

export const useBillingDetailMutation = (options?: UseMutationOptions<BillingDetailResponse, CBDCAxiosError, BillingDetailParams>) => {
  const mutation = useMutation<BillingDetailResponse, CBDCAxiosError, BillingDetailParams>({
    ...options,
    mutationFn: (params: BillingDetailParams) => billingDetail(params),
  });

  return {
    ...mutation,
  };
};
