package com.yidian.common

import android.app.Application
import cn.jpush.android.api.JPushInterface
import com.yidian.common.http.ApiAddHeadersInterceptor
import com.yidian.common.http.BaseURLs
import com.yidian.common.http.HttpCommonParamsUtils
import com.yidian.common.utils.EncryptUtil
import com.yidian.common.utils.StringUtils
import com.yidian.common.utils.SystemUtil
import com.yidian.http.ServiceFactory
import com.yidian.yac.ftdevicefinger.core.FtDeviceFingerManager


open class YacBaseApplication : Application() {
    companion object {
        lateinit var context: Application
    }


    override fun onCreate() {
        super.onCreate()
        context= this
        FtDeviceFingerManager.init(this)
        //init http
        ServiceFactory.getInstance().init(true, BaseURLs.BASE_URL, 10, 10)
        ServiceFactory.getInstance().addInterceptor(ApiAddHeadersInterceptor())
        //初始化通用网络参数
        HttpCommonParamsUtils.deviceId = SystemUtil.calcDeviceId(context)
        HttpCommonParamsUtils.imei = SystemUtil.getPhoneIMEI(context)
        HttpCommonParamsUtils.mid = SystemUtil.getMacAddress()
        HttpCommonParamsUtils.androidId = SystemUtil.getAndroidID(context)
        HttpCommonParamsUtils.serialNumber = SystemUtil.getSerialNumber()
        HttpCommonParamsUtils.version = StringUtils.formatVersion(SystemUtil.getVerName(context))
        HttpCommonParamsUtils.deviceFinger = FtDeviceFingerManager.getDeviceFinger()?:""
        HttpCommonParamsUtils.OS = android.os.Build.VERSION.RELEASE
        HttpCommonParamsUtils.targetSdkVersion = this.applicationInfo.targetSdkVersion
        HttpCommonParamsUtils.x_digest = EncryptUtil.xDigest(
            HttpCommonParamsUtils.deviceId!!,
            HttpCommonParamsUtils.packageName
        )!!

//        //极光推送
//        JPushInterface.setDebugMode(true)
//        JPushInterface.init(this)
    }
}