package com.atmob.flutter_umeng;

import android.content.Context;
import android.util.Log;

import androidx.annotation.NonNull;

import com.atmob.channelreader.ChannelReader;
import com.umeng.analytics.MobclickAgent;
import com.umeng.commonsdk.UMConfigure;

import java.util.Map;

public class UmengHelper {

    private static final String TAG = "UmengHelper";

    private UmengHelper() {

    }

    public static void initCommon(@NonNull Context context, String appKey) {
        Log.d(TAG, "initCommon");
        initAfterGrantedAgreement(context, appKey);
    }

    public static void initAfterGrantedAgreement(@NonNull Context context, String appKey) {
        UMConfigure.init(context, appKey, ChannelReader.getChannel(context), UMConfigure.DEVICE_TYPE_PHONE, null);//last param is PushSecretKey
    }


    /**
     * 上报用户是否同意隐私政策
     *
     * @param granted 是否同意
     */
    public static void submitPolicyGrantResult(Context context, boolean granted) {
        Log.d(TAG, "submitPolicyGrantResult:granted=" + granted);
        UMConfigure.submitPolicyGrantResult(context.getApplicationContext(), granted);
    }

    /**
     * 事件上报
     *
     * @param eventId 事件id
     */
    public static void reportEvent(Context context, String eventId) {
        MobclickAgent.onEvent(context, eventId);
    }

    /**
     * 携带信息的事件上报
     *
     * @param eventId 事件id
     * @param map     额外信息, object类型由第一次上报时的为准, 后续不能更改
     */
    public static void reportEvent(Context context, String eventId, Map<String, Object> map) {
        MobclickAgent.onEventObject(context, eventId, map);
    }
}
