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

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

export const usePaymentNotificationDataMutation = (options?: UseMutationOptions<PaymentNotificationDataResponse, NiceAxiosError, PaymentNotificationDataParams>) => {
  const mutation = useMutation<PaymentNotificationDataResponse, NiceAxiosError, PaymentNotificationDataParams>({
    ...options,
    mutationFn: (params: PaymentNotificationDataParams) => paymentNotificationData(params),
  });

  return {
    ...mutation,
  };
};