package com.doverfuelingsolutions.issp.api

import com.doverfuelingsolutions.issp.utils.sp.SPKeys
import com.doverfuelingsolutions.issp.utils.sp.SPUtil

class WayneApiConfig {

    companion object {

        const val timeoutConnect = 120L
        const val timeoutAll = 25L //超时时间由原本的 180 秒改为 20 秒

        //支付的超时时间长一点，有时是等待输入密码导致响应时间比较长
        //设置不同的时间，后面方便从不同的时间来判断是哪个时间超时
        const val timeoutPayCall = 70L  //超时时间
        const val timeoutPayWrite = 60L //写超时
        const val timeoutPayRead = 65L  //读超时

        const val PATH_BASE_TOKEN = "token"
        const val PATH_BASE_DEVICE_SESSION = "api/DeviceManagement/GetCurrentSessionInfo"
        const val PATH_TRX_TRANS = "api/Transactions"
        const val PATH_TRX_DISCOUNT = "api/transactions/{trxid}/validatePromotion"
        const val PATH_TRX_PAY_PARAM = "api/mops/thirdParty"
        const val PATH_CONFIG_DESC = "api/Config/description"
        const val PATH_CONFIG_FILE = "api/Config/file"
        const val PATH_CONFIG = "api/config"
        const val PATH_BARCODE = "api/products/barcode/{id}"
        const val PATH_PAY_BY_ID = "api/Transactions/{id}/payment"
        const val PATH_VERSION_FILE = "isspt/version.json"
        const val POS_TICKET_INFO = "api/receipt/{trxId}/maxChar/40"

        const val CONFIG_DEVICE = "PosRemoteConfig"
        const val CONFIG_LOGO = "SiteLogo"

        const val CHECK_ORDER_STATE = "api/TransactionStatus/GetTransactionStatus"

        // 默认值 - 云端
        const val DOMAIN_DEFAULT = "http://ipos.biz"
        const val DOMAIN_DEFAULT_RELEASE = "http://tkhs.net.cn"
        const val PORT_BASE_DEFAULT = "8698"
        const val PORT_TRX_DEFAULT = "8699"
        const val PORT_CONFIG_DEFAULT = "8889"
        const val PORT_ASSETS_DEFAULT = "8080"
        const val PORT_MIDDLE_TOOL_DEFAULT = "8721"
        private const val HOST_BASE_DEFAULT = "$DOMAIN_DEFAULT:$PORT_BASE_DEFAULT"
        private const val HOST_TRX_DEFAULT = "$DOMAIN_DEFAULT:$PORT_TRX_DEFAULT"
        private const val HOST_CONFIG_DEFAULT = "$DOMAIN_DEFAULT:$PORT_CONFIG_DEFAULT"
        private const val HOST_ASSETS_DEFAULT = "$DOMAIN_DEFAULT:$PORT_ASSETS_DEFAULT"
        private const val HOST_MIDDLE_TOOL_DEFAULT = "$DOMAIN_DEFAULT_RELEASE:$PORT_MIDDLE_TOOL_DEFAULT"
        // 默认值 - 中控
        const val MIDDLE_IP_DEFAULT = "192.168.1.80"
        const val MIDDLE_PORT_DEFAULT = "4711"
        const val MIDDLE_WORKSTATION_ID = "8888"
        // 默认值 - 加油信息
        const val FUEL_IP_DEFAULT = "192.168.1.80"
        const val FUEL_PORT_DEFAULT = "8384"

        // 服务发现的 APIName
        const val Api_GetPumpsLayout = "GetPumpsLayout"
        const val Api_AccumulationInfo = "GetFuelSaleTrxDetailsAsync"

        // URL
        const val URL_SERVICE_DISCOVER = "u/?apitype=service&an=ShowMeApi&pn=ProcessorsDispatcher&en=Edge.Core.Processor.Dispatcher.DefaultDispatcher"

        // 实时值
        val HOST_BASE: String get() {
            val domain = SPUtil.getString(SPKeys.SERVER_DOMAIN)
            val port = SPUtil.getString(SPKeys.SERVER_PORT_BASE)
            return if (domain.isEmpty() || port.isEmpty()) HOST_BASE_DEFAULT else "$domain:$port"
        }
        val HOST_TRX: String get() {
            val domain = SPUtil.getString(SPKeys.SERVER_DOMAIN)
            val port = SPUtil.getString(SPKeys.SERVER_PORT_TRX)
            return if (domain.isEmpty() || port.isEmpty()) HOST_TRX_DEFAULT else "$domain:$port"
        }
        val HOST_CONFIG: String get() {
            val domain = SPUtil.getString(SPKeys.SERVER_DOMAIN)
            val port = SPUtil.getString(SPKeys.SERVER_PORT_CONFIG)
            return if (domain.isEmpty() || port.isEmpty()) HOST_CONFIG_DEFAULT else "$domain:$port"
        }
        val HOST_ASSETS: String get() {
            val domain = SPUtil.getString(SPKeys.SERVER_DOMAIN)
            val port = SPUtil.getString(SPKeys.SERVER_PORT_ASSETS)
            return if (domain.isEmpty() || port.isEmpty()) HOST_ASSETS_DEFAULT else "$domain:$port"
        }
        val CHECK_ORDER_BASE:String get() {
            val domain = SPUtil.getString(SPKeys.SERVER_DOMAIN)
            val port = SPUtil.getString(SPKeys.SERVER_PORT_TOOL)
            return if (domain.isEmpty() || port.isEmpty()) HOST_MIDDLE_TOOL_DEFAULT else "$domain:$port"

//            return "http://tkhs.net.cn:8721"  //生产
//            return "http://47.97.120.160:8721"//测试
//            return "http://47.101.220.106:8721" //开发
        }
    }
}