package com.wdkl.ncs.android.middleware.api

import com.wdkl.ncs.android.lib.base.BaseApplication
import com.wdkl.ncs.android.middleware.config.WdklNcsConfigCenter
import com.wdkl.ncs.android.middleware.utils.CommonUtils

/**
 * @author LDD
 * @Date   2018/8/21 下午4:38
 * @From   com.wdkl.ncs.android.middleware.api
 * @Note   Url控制器接口
 */
interface UrlManager {

    /// host地址
    val base  : String

    /// 买家
    val buyer : String

    /// 基础Api
    val basic : String

    /**
     * @author LDD
     * @Date   2018/8/21 下午4:46
     * @From   UrlManager
     * @Note   伴生对象
     */
    companion object {

        /**
         * @author LDD
         * @From   UrlManager
         * @Date   2018/8/21 下午4:47
         * @Note   构架Url控制器
         */
        fun build() : UrlManager{
            /*if (WdklNcsConfigCenter.INSTANCE.APP_DEV){
                return DevUrlManager()
            }else{
                return ProUrlManager()
            }*/

            return ProUrlManager()
        }

    }

}

/**
 * @author LDD
 * @Date   2018/8/21 下午4:38
 * @From   com.wdkl.ncs.android.middleware.api
 * @Note   开发模式Url控制器
 */
private class DevUrlManager : UrlManager{

    override val base: String
        get() = "http://api.%s.wdkl.natapp1.cc/"

    override val buyer: String
        //get() = "${base}:7002/"
        get() = String.format(base,"buyer")

    override val basic: String
        //get() = "${base}:7000/"
        get() = String.format(base,"base")
}

/**
 * @author LDD
 * @Date   2018/8/21 下午4:38
 * @From   com.wdkl.ncs.android.middleware.api
 * @Note   生产模式Url控制器
 */
private class ProUrlManager : UrlManager{
    val url: String = CommonUtils.getUrl(BaseApplication.appContext)
    val port: String = CommonUtils.getUrlPort(BaseApplication.appContext)

    override val base: String
        get() = "http://$url:$port/"

        //get() = "http://api.%s.wdklian.com/"
        //get() = "http://172.28.100.100:8006/"
        //get() = "http://8.129.220.143:8006/"
        //get() = "http://172.168.0.254:8006/"
        //get() = "http://119.23.151.229:8006/"
        //get() = "http://192.168.101.1:8006/"

    override val buyer: String
        get() = String.format(base,"buyer")

    override val basic: String
        get() = String.format(base,"base")
}