package com.gh.gamecenter.common.utils

import com.alibaba.android.arouter.launcher.ARouter
import com.gh.gamecenter.common.constant.Constants
import com.gh.gamecenter.common.BuildConfig
import com.gh.gamecenter.common.constant.RouteConsts
import com.gh.gamecenter.core.provider.IBuildConfigProvider
import com.gh.gamecenter.core.utils.SPUtils

object EnvHelper {

    // API 环境是否为测试环境
    @JvmStatic
    val isDevEnv: Boolean by lazy {
        SPUtils.getBoolean(Constants.SP_IS_DEV_ENV, false)
    }

    @JvmStatic
    fun getHost(): String {
        val buildConfig =
            ARouter.getInstance().build(RouteConsts.provider.buildConfig).navigation() as? IBuildConfigProvider
        return if (!PackageFlavorHelper.IS_TEST_FLAVOR) {
            buildConfig?.getApiHost() ?: ""
        } else {
            if (isDevEnv) {
                buildConfig?.getDevApiHost() ?: ""
            } else {
                buildConfig?.getApiHost() ?: ""
            }
        }
    }

    @JvmStatic
    fun getVHost(): String {
        val buildConfig =
            ARouter.getInstance().build(RouteConsts.provider.buildConfig).navigation() as? IBuildConfigProvider
        return if (!PackageFlavorHelper.IS_TEST_FLAVOR) {
            buildConfig?.getVDevApiHost() ?: ""
        } else {
            if (isDevEnv) {
                buildConfig?.getVDevApiHost() ?: ""
            } else {
                buildConfig?.getVApiHost() ?: ""
            }
        }
    }

    @JvmStatic
    fun getNewHost(): String {
        val buildConfig =
            ARouter.getInstance().build(RouteConsts.provider.buildConfig).navigation() as? IBuildConfigProvider
        return if (!PackageFlavorHelper.IS_TEST_FLAVOR) {
            buildConfig?.getNewApiHost() ?: ""
        } else {
            if (isDevEnv) {
                buildConfig?.getNewDevApiHost() ?: ""
            } else {
                buildConfig?.getNewApiHost() ?: ""
            }
        }
    }

}