package com.swago.baseswago.constant

import com.google.gson.Gson
import com.swago.baseswago.BuildConfig
import com.swago.baseswago.model.ConfigModel
import com.swago.baseswago.util.AppContext
import com.swago.baseswago.util.SpUtil
import java.io.File

/**
 *@date 2021/8/14 14:06
 *description:
 */
object UrlConstant {

    var BASE_URL = if (BuildConfig.DEBUG) {
//            "http:test-api.swago.cn"
//            "http:huawei.swago.cn"
        "https://pro-api.swago.cn"
    } else {
            "https://pro-api.swago.cn"
        }

    private val BASE_WEB_URL by lazy {
        if (BuildConfig.DEBUG) {
            "http://swago-h5.codedreamit.com"
        } else {
            "https://h5.swago.cn"
        }
    }


    private val gson by lazy {
        Gson()
    }

    //声网id
    private var agoraId = ""

    fun getConfigModel():ConfigModel?{
        val infoJson = SpUtil.readString("configModel")
        return if (infoJson.isNullOrEmpty()) {
            null
        } else {
            gson.fromJson(infoJson, ConfigModel::class.java)
        }
    }

    fun getAgoraId():String{
        if (agoraId.isEmpty()){
            agoraId = getConfigModel()?.agoral_app_id?:""
        }
        // ！！！ 为了防止获取到的agoraId不是空的这里如果获取到之后还是空  那么给个默认值
        if (agoraId.isEmpty()){
            agoraId = "ae14303e10bd4d98acbd8f63e09fb19b"
        }
        return agoraId
    }

    fun setAgoraId(agoraId:String){
        this.agoraId = agoraId
    }

    //腾讯IM
    private var imId = 0

    fun getImId():Int{
        if (imId==0){
            imId = getConfigModel()?.im_app_id?:0
        }
        return imId
    }

    fun setImId(imId:Int){
        this.imId = imId
    }

    const val USER_AGREEMENT = "http://agreement.swago.cn/html/userAgreement.html"
    const val USER_PRIVACY = "http://agreement.swago.cn/html/privacyPolicy.html"

    val TOP_UP = "${BASE_WEB_URL}/recharge/detail"
    val WITHDRAW = "${BASE_WEB_URL}/withdrawal" //主播家族长跳这个
    val WITHDRAW_CUSTOMER = "${BASE_WEB_URL}/withdrawal/customer"//普通用户跳这个

    var appGameRootPath =
        AppContext.getContext().getExternalFilesDir("")?.absolutePath + File.separator + "gameFile"



    var lottieResourcePath =
        AppContext.getContext().getExternalFilesDir("")?.absolutePath + File.separator + "lottie"
    var lottieDownloadUrl = ""
}