package com.datarecovery.master.sdk.central;

import android.content.Context;

import com.atmob.analytics.AtmobAnalytics;
import com.atmob.central.AtmobCentral;
import com.atmob.central.AtmobCentralConfig;
import com.atmob.common.thread.ThreadPoolUtil;
import com.atmob.compliance.AtmobCompliance;
import com.datarecovery.master.BuildConfig;
import com.datarecovery.master.data.consts.Constants;

import java.util.Map;

public class AtmobCentralHelper {
    public static void init(Context context, String channel, int appId, int tgPlatformId) {
        AtmobCentral.init(context, new AtmobCentralConfig.Builder()
                .appKey(BuildConfig.ATMOB_CENTRAL_KEY)
                .debug(BuildConfig.DEBUG)
                .centralServer(Constants.Atmob_Server_Base_URL)
                .channel(channel)
                .appId(appId)
                .tgPlatform(tgPlatformId)
                .complianceStrategy(AtmobCompliance.Strategy.CHINA)
                .executorService(ThreadPoolUtil.getInstance())
                .build());
    }

    public static void onPolicyGranted(boolean grand) {
        AtmobCentral.onPolicyGrant(grand);
    }

    public static void trackEvent(String event, Map<String, Object> params) {
        AtmobAnalytics.getInstance().trackEvent(event, params);
    }

    public static void trackPay(String itemName, String orderNo, String currency, int priceCent, int paymentWay) {
        AtmobAnalytics.getInstance().trackPay(itemName, orderNo, currency, priceCent, getPaymentWay(paymentWay));
    }

    private static String getPaymentWay(int paymentWay) {
        switch (paymentWay) {
            case Constants.PAYMENT_WAY_WECHAT:
            case Constants.PAYMENT_WAY_WECHAT_SCAN:
                return AtmobAnalytics.PAYMENT_WECHAT;
            case Constants.PAYMENT_WAY_ALIPAY:
            case Constants.PAYMENT_WAY_ALIPAY_SCAN:
                return AtmobAnalytics.PAYMENT_ALIPAY;
        }
        return "";
    }
}
