
package com.kytepos.rn.redirapp;

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

import sdk.com.redirapp.Redirapp;

public class RNRedirappModule extends ReactContextBaseJavaModule {

  private final ReactApplicationContext reactContext;
  private String applicationId = null;

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

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

  @ReactMethod
  public void init(String applicationId) {
    this.applicationId = applicationId;
    Redirapp.init(this.reactContext, applicationId);
  }

  @ReactMethod
  public void logPurchase(ReadableMap request) {
      Double amount = request.getDouble("amount");
      String sku = request.getString("sku");
      Redirapp.logPurchase(amount, sku);
  }

  @ReactMethod
  public void logPurchaseWithCurrency(ReadableMap request) {
      Double amount = request.getDouble("amount");
      String sku = request.getString("sku");
      String currency = request.getString("currency");
      Redirapp.logPurchase(amount, currency, sku);
  }
}