package com.gh.gamecenter.login.provider

import android.content.Context
import com.alibaba.android.arouter.facade.annotation.Route
import com.cmic.gen.sdk.auth.GenAuthnHelper
import com.gh.gamecenter.common.constant.RouteConsts
import com.gh.gamecenter.core.provider.IQuickLoginProvider
import com.gh.gamecenter.login.utils.QuickLoginHelper
import org.json.JSONException

@Route(path = RouteConsts.provider.quickLogin, name = "一键登录暴露服务")
class QuickLoginProviderImpl : IQuickLoginProvider {

    override fun startLogin(context: Context, entrance: String) {
        QuickLoginHelper.startLogin(context, entrance)
    }

    override fun isOpenMobileData(context: Context): Boolean {
        val helper = GenAuthnHelper.getInstance(context)
        val jsonObject = helper.getNetworkType(context)
        val net: Int
        try {
            net = jsonObject.getString("networktype").toInt()
            if (net == 1 || net == 3) return true
        } catch (e: JSONException) {
            e.printStackTrace()
        }
        return false
    }

    override fun init(context: Context?) {
        // Do nothing
    }
}