package com.yidianling.ydlcommon.custom;

import android.content.Context;
import com.ydl.pushserver.pushagent.YdlPushAgent;
import com.ydl.pushserver.pushagent.network.pack.RegisterEventBean;
import com.yidianling.ydlcommon.core.base.BaseApplication;
import com.yidianling.common.tools.LogUtil;
import com.yidianling.common.tools.RxAppTool;
import com.yidianling.common.tools.RxDeviceTool;
import com.yidianling.ydlcommon.BuildConfig;
import com.yidianling.ydlcommon.custom.router.YdlCommonOut;
import com.yidianling.ydlcommon.custom.router.YdlCommonRouterManager;
import com.yidianling.ydlcommon.custom.tool.JPushUtils;

//埋点工具类
public class YdlBuryPointUtil {

    //初始化
    public static void init(Context context){
        try {

//            if (BuildConfig.DEBUG){
//                YdlPushAgent.setDebugAdree("192.168.70.31",3691);
//            }

            RegisterEventBean registerEventBean = new RegisterEventBean();
            registerEventBean.setAppId(context.getPackageName());
            registerEventBean.setAppVersion(RxAppTool.getAppVersionName(context));
            String channelId = JPushUtils.INSTANCE.getRegistrationID();
            registerEventBean.setDeviceId(channelId);
            registerEventBean.setFfrom(YdlCommonOut.Companion.getChannelName());
            registerEventBean.setIp(RxDeviceTool.getIP(context));
            registerEventBean.setPlatform("android");
            registerEventBean.setSystem("android");
            registerEventBean.setSysVersion(RxDeviceTool.getOsBuileVersion());
            registerEventBean.setUid(YdlCommonRouterManager.INSTANCE.getYdlCommonRoute().getUid()+"");

            LogUtil.d(registerEventBean.toString());
            YdlPushAgent.init(registerEventBean, BuildConfig.DEBUG);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    //重新登录
    public static void reLogin(){
        try {
            RegisterEventBean registerEventBean = new RegisterEventBean();
            registerEventBean.setAppId(BaseApplication.Companion.getApp().getPackageName());
            registerEventBean.setAppVersion(RxAppTool.getAppVersionName(BaseApplication.Companion.getApp()));
            String channelId = JPushUtils.INSTANCE.getRegistrationID();
            registerEventBean.setDeviceId(channelId);
            registerEventBean.setFfrom(YdlCommonOut.Companion.getChannelName());
            registerEventBean.setIp(RxDeviceTool.getIP(BaseApplication.Companion.getApp()));
            registerEventBean.setPlatform("android");
            registerEventBean.setSystem("android");
            registerEventBean.setSysVersion(RxDeviceTool.getOsBuileVersion());
            registerEventBean.setUid(YdlCommonRouterManager.INSTANCE.getYdlCommonRoute().getUid()+"");
            YdlPushAgent.reLogin(registerEventBean);

            LogUtil.d(registerEventBean.toString());
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    //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);
    }
}
