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

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

export const usePaymentNonCardMutation = (options?: UseMutationOptions<PaymentNonCardResponse, NiceAxiosError, PaymentNonCardParams>) => {
  const mutation = useMutation<PaymentNonCardResponse, NiceAxiosError, PaymentNonCardParams>({
    ...options,
    mutationFn: (params: PaymentNonCardParams) => paymentNonCard(params),
  });

  return {
    ...mutation,
  };
};
