import axios from 'axios';
import { API_URL_PAYMENT } from '@/shared/api/api-url-payment';
import { resultify } from '@/shared/lib/resultify';
import { CBDCAxiosError } from '@/shared/@types/error';
import { 
  PaymentNonCardParams,
  PaymentNonCardResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const paymentNonCard = (params: PaymentNonCardParams) => {
  return resultify(
    axios.post<PaymentNonCardResponse>(API_URL_PAYMENT.paymentNonCard(), params),
  );
};

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

  return {
    ...mutation,
  };
};
