package com.ydl.ydlcommon.utils;

import android.content.Context;
import com.ydl.burypointlib.BuryPointHelper;
import com.ydl.pushserver.pushagent.YdlPushAgent;
import com.ydl.pushserver.pushagent.network.pack.RegisterEventBean;
import com.ydl.ydlcommon.BuildConfig;
import com.ydl.ydlcommon.modular.ModularServiceManager;
import com.ydl.ydlcommon.router.YdlCommonOut;
import com.yidianling.common.tools.RxAppTool;
import com.yidianling.common.tools.RxDeviceTool;
import com.yidianling.common.tools.RxNetTool;
//import com.ydl.burypointlib.BuryPointHelper;

//埋点工具类
public class YdlBuryPointUtil {

    private static Context context;

    //初始化
    public static void init(Context context1){
        try {
            context = context1;
            if (BuildConfig.DEBUG){
                YdlPushAgent.setDebugAdree("47.97.49.44",8094);
            }

            RegisterEventBean registerEventBean = new RegisterEventBean();
            registerEventBean.setAppId(context.getPackageName());
            registerEventBean.setAppVersion(RxAppTool.getAppVersionName(context));
            String channelId = JPushUtils.INSTANCE.getRegistrationID();
            registerEventBean.setDeviceId(channelId);
            registerEventBean.setManufacturer(RxDeviceTool.getBuildMANUFACTURER());
            registerEventBean.setChannel(YdlCommonOut.Companion.getChannelName());
            registerEventBean.setOs("Android");
            registerEventBean.setModel(RxDeviceTool.getBuildBrandModel());
            registerEventBean.setOsVersion(RxDeviceTool.getOsBuileVersion());
            registerEventBean.setUid(ModularServiceManager.INSTANCE.getPlatformUserService().getUser().getUserId()+"");
            registerEventBean.setScreenHeight(RxDeviceTool.getScreenHeight(context));
            registerEventBean.setScreenWidth(RxDeviceTool.getScreenWidth(context));
            registerEventBean.setWifi(RxNetTool.getNetWorkTypeName(context));

            LogUtil.d(registerEventBean.toString());

            YdlPushAgent.init(registerEventBean,BuildConfig.DEBUG);

            BuryPointHelper.setDebug(BuildConfig.DEBUG,BuildConfig.DEBUG,true,BuildConfig.DEBUG);
            BuryPointHelper.init();

        }catch (Exception e){
            e.printStackTrace();
        }
    }

    //重新登录
    public static void reLogin(){
        try {
            RegisterEventBean registerEventBean = new RegisterEventBean();
            registerEventBean.setAppId(context.getPackageName());
            registerEventBean.setAppVersion(RxAppTool.getAppVersionName(context));
            String channelId = JPushUtils.INSTANCE.getRegistrationID();
            registerEventBean.setDeviceId(channelId);
            registerEventBean.setManufacturer(RxDeviceTool.getBuildMANUFACTURER());
            registerEventBean.setChannel(YdlCommonOut.Companion.getChannelName());
            registerEventBean.setOs("Android");
            registerEventBean.setModel(RxDeviceTool.getBuildBrandModel());
            registerEventBean.setOsVersion(RxDeviceTool.getOsBuileVersion());
            registerEventBean.setUid(ModularServiceManager.INSTANCE.getPlatformUserService().getUser().getUserId()+"");
            registerEventBean.setScreenHeight(RxDeviceTool.getScreenHeight(context));
            registerEventBean.setScreenWidth(RxDeviceTool.getScreenWidth(context));
            registerEventBean.setWifi(RxNetTool.getNetWorkTypeName(context));
            YdlPushAgent.reLogin(registerEventBean);

            LogUtil.d("reLogin:"+registerEventBean.toString());
        }catch (Exception e){
            LogUtil.e("reLogin:"+e.getMessage());
        }
    }

    //pv埋点
    public static void sendPv(String pageViewId){
        YdlPushAgent.sendPvEvent(pageViewId);
        LogUtil.d(pageViewId);
    }

    //click埋点
    public static void sendClick(String eventId){
        LogUtil.d(eventId);
        YdlPushAgent.sendClickEvent(eventId);
    }
}
