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

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

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

  return {
    ...mutation,
  };
};
