package ai.causalfoundry.rnsdk.payments;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;

import ai.causalfoundry.android.sdk.payments.builders.CfLogDeferredPaymentEvent;
import ai.causalfoundry.android.sdk.payments.builders.CfLogPaymentMethodEvent;


public class CfLogPayments extends ReactContextBaseJavaModule {

    private final ReactApplicationContext reactContext;

    public CfLogPayments(ReactApplicationContext reactContext) {
        super(reactContext);
        this.reactContext = reactContext;
    }

    @Override
    public String getName() {
        return "CfLogPayments";
    }


    /**
     * logDeferredPaymentEvent is to log events for payments when they undergo processing and
     * processed completed or canceled. This log is for use cases where we have to Buy Now and Pay Later
     * which means that customers can buy the items now and pay the amount at a later date.
     *
     * @param paymentId         is required to set the id for the payment in the log, Id should be in
     *                          string and must be per the catalog provided.
     * @param type              is required to set the type of the payment is being selected.
     *                          By default SDK provides an enum class to use as PaymentAction.
     * @param action            is used to specify the action performed on the payments screen,
     *                          there can be multiple types of actions that can include init payment
     *                          process, cancel payment processing or upload the receipt to a bank deposit.
     *                          By default SDK provides an enum class to use as PaymentAction.
     * @param accountBalance    is required to log the current balance of the user. Amount format
     *                          should be per the currency selected.
     * @param payment_amount    is required to log the total price of the payment being logged.
     *                          Amount format should be per the currency selected.
     * @param currency          is required to log the currency for the payment logged.
     *                          Currency should be in ISO 4217 format. For ease, SDK provides the
     *                          enums to log the currency so that it would be easy to log. You can
     *                          also use the string function to provide the currency.
     * @param is_successful     is required to log if the payment is processed successfully or not.
     * @param meta              is to send any other data you want to send with the ingest, can be null.
     * @param updateImmediately is default set to true, you can use that to log events when the app
     *                          goes in the background or closed.
     */
    @ReactMethod
    public void logDeferredPaymentEvent(String orderId, String paymentId,
                                        String type, String action,
                                        float accountBalance, float payment_amount,
                                        String currency, Boolean is_successful,
                                        String meta, Boolean updateImmediately) {
        new CfLogDeferredPaymentEvent.Builder()
                .setPaymentId(paymentId)
                .setOrderId(orderId)
                .setPaymentMethod(type)
                .setPaymentAction(action)
                .setAccountBalance(accountBalance)
                .setPaymentAmount(payment_amount)
                .setCurrency(currency).isSuccessful(is_successful)
                .setMeta(meta).updateImmediately(updateImmediately)
                .build();
    }

    /**
     * logPaymentMethodEvent is to log events for payments. Which method of the payment is
     * selected for the order.
     *
     * @param paymentId         is required to set the id for the payment in log, if not
     *                          then provide payment_<user_id>
     * @param orderId           is required to set the id for the order in log, Id should be in string
     *                          and must be in accordance to the catalog provided.
     * @param paymentMethod     is required to set the type of the payment is being selected.
     *                          By default SDK provides an enum class to use as PaymentAction.
     * @param paymentAction     is required to log the action on the payment being logged.
     * @param payment_amount    is required to log the total price of the payment being logged.
     *                          Amount format should be per the currency selected.
     * @param currency          is required to log the currency for the payment logged.
     *                          Currency should be in ISO 4217 format. For ease, SDK provides the
     *                          enums to log the currency so that it would be easy to log. You can
     *                          also use the string function to provide the currency.
     * @param meta              is to send any other data you want to send with the ingest, can be null.
     * @param updateImmediately is default set to true, you can use that to log events when the app
     *                          goes in the background or closed.
     */
    @ReactMethod
    public void logPaymentMethodEvent(String paymentId, String orderId, String paymentMethod,
                                      String paymentAction,
                                        float payment_amount,
                                        String currency,
                                        String meta, Boolean updateImmediately) {
        new CfLogPaymentMethodEvent.Builder()
                .setPaymentId(paymentId)
                .setOrderId(orderId)
                .setPaymentMethod(paymentMethod)
                .setAction(paymentAction)
                .setPaymentAmount(payment_amount)
                .setCurrency(currency)
                .setMeta(meta).updateImmediately(updateImmediately)
                .build();
    }

}