package cn.yyxx.eyuangame.core.network

import android.content.Context
import cn.yyxx.eyuangame.base.utils.ParamsUtils
import cn.yyxx.support.HostModelUtils

/**
 * @author #Suyghur.
 * Created on 2021/06/17
 */
object Host {

    private var DEFAULT_ONLINE_HOST = ""
    private var DEFAULT_TEST_HOST = ""

    private const val DEFAULT_ONLINE_HOST_HK = "https://sdkapi.eyuangame.com"
    private const val DEFAULT_TEST_HOST_HK = "https://testsdkapi.eyuangame.com"

    private const val DEFAULT_ONLINE_HOST_VN = "https://sdkapi.aiigame.com"
    private const val DEFAULT_TEST_HOST_VN = "https://testsdkapi.aiigame.com"

    var HOST = ""

    /**
     * 默认线上环境
     */
    var IP_MODEL = 3

    /**
     * 默认港澳台
     */
    var ENV = 1

    const val BASIC_ROUTE_INIT_SDK = "activate"
    const val BASIC_ROUTE_LOGIN = "member_login"
    const val BASIC_ROUTE_THIRD_PART_LOGIN = "third_plat_login"
    const val BASIC_ROUTE_REGISTER = "member_register"
    const val BASIC_ROUTE_BIND_ACCOUNT = "bind_member_user"
    const val BASIC_ROUTE_BIND_PHONE = "bind_phone"
    const val BASIC_ROUTE_GET_CAPTCHA = "phone_captcha"
    const val BASIC_ROUTE_FORGET_PWD = "forgot_pwd"
    const val BASIC_ROUTE_MODIFY_PWD = "modify_pwd"
    const val BASIC_ROUTE_CREATE_ORDER = "iap_init"
    const val BASIC_ROUTE_NOTIFY_ORDER = "iap_notify"
    const val BASIC_ROUTE_NOTIFY_REWARD = ""
    const val BASIC_ROUTE_SUBMIT_ROLE_INFO = "game_role_report"


    fun initHostModel(context: Context) {
        IP_MODEL = HostModelUtils.getHostModel(context)
        ENV = ParamsUtils.getDoMainEnv(context)
        setDefaultHost()
    }

    fun originHost(url: String): Boolean {
        return (url.startsWith(DEFAULT_ONLINE_HOST_HK)
                || url.startsWith(DEFAULT_TEST_HOST_HK)
                || url.startsWith(DEFAULT_ONLINE_HOST_VN)
                || url.startsWith(DEFAULT_TEST_HOST_VN))

    }

    private fun setDefaultHost() {
        DEFAULT_ONLINE_HOST = when (ENV) {
            Env.HK -> DEFAULT_ONLINE_HOST_HK
            Env.VN -> DEFAULT_ONLINE_HOST_VN
            else -> DEFAULT_ONLINE_HOST_HK
        }
        DEFAULT_TEST_HOST = when (ENV) {
            Env.HK -> DEFAULT_TEST_HOST_HK
            Env.VN -> DEFAULT_TEST_HOST_VN
            else -> DEFAULT_TEST_HOST_HK
        }
        HOST = when (IP_MODEL) {
            HostModelUtils.ENV_TEST -> DEFAULT_TEST_HOST
            HostModelUtils.ENV_ONLINE -> DEFAULT_ONLINE_HOST
            else -> DEFAULT_ONLINE_HOST
        }
    }

    object Env {
        const val HK = 1
        const val VN = 2
    }
}