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 { 
  PaymentInstallmentParams,
  PaymentInstallmentResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const paymentInstallment = (params: PaymentInstallmentParams) => {
  return resultify(
    axios.post<PaymentInstallmentResponse>(API_URL_PAYMENT.paymentInstallment(), params),
  );
};

export const usePaymentInstallmentMutation = (options?: UseMutationOptions<PaymentInstallmentResponse, CBDCAxiosError, PaymentInstallmentParams>) => {
  const mutation = useMutation<PaymentInstallmentResponse, CBDCAxiosError, PaymentInstallmentParams>({
    ...options,
    mutationFn: (params: PaymentInstallmentParams) => paymentInstallment(params),
  });

  return {
    ...mutation,
  };
};
