import axios from 'axios';
import { API_URL_TRANSACTION } from '@/shared/api/api-url-transaction';
import { resultify } from '@/shared/lib/resultify';
import { NiceAxiosError } from '@/shared/@types/error';
import { 
  BillingDetailParams,
  BillingDetailResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';
import { getHeaderUserAgent } from '@/shared/constants/url';

export const billingDetail = (params: BillingDetailParams) => {
  let headerOptions = {
    menuId: 34,
    apiType: 'SELECT'
  };
  let options = {
    headers: {
      'X-User-Agent': getHeaderUserAgent(headerOptions)
    }
  };
  return resultify(
    axios.post<BillingDetailResponse>(API_URL_TRANSACTION.billingDetail(), params, options),
  );
};

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

  return {
    ...mutation,
  };
};
