import axios from 'axios';
import { API_URL_PAYMENT } from '@/shared/api/api-url-payment';
import { resultify } from '@/shared/lib/resultify';
import { NiceAxiosError } from '@/shared/@types/error';
import { 
  PaymentInstallmentDetailParams,
  PaymentInstallmentDetailResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';
import { getHeaderUserAgent } from '@/shared/constants/url';

export const paymentInstallmentDetail = (params: PaymentInstallmentDetailParams) => {
  let headerOptions = {
    menuId: 42,
    apiType: 'SELECT'
  };
  let options = {
    headers: {
      'X-User-Agent': getHeaderUserAgent(headerOptions)
    }
  };
  return resultify(
    axios.post<PaymentInstallmentDetailResponse>(API_URL_PAYMENT.paymentInstallmentDetail(), params, options),
  );
};

export const usePaymentInstallmentDetailMutation = (options?: UseMutationOptions<PaymentInstallmentDetailResponse, NiceAxiosError, PaymentInstallmentDetailParams>) => {
  const mutation = useMutation<PaymentInstallmentDetailResponse, NiceAxiosError, PaymentInstallmentDetailParams>({
    ...options,
    mutationFn: (params: PaymentInstallmentDetailParams) => paymentInstallmentDetail(params),
  });

  return {
    ...mutation,
  };
};
