package com.miya.fastcashier.net

import android.text.TextUtils
import com.miya.fastcashier.BuildConfig
import com.miya.fastcashier.beans.SelfCashierTerminalConfig

object ApiConfig {
    private const val BASE_URL = "https://hhms.miyapay.com/"
    private const val BASE_URL_4_TEST = "https://hhmspre.miyapay.com/"

    @JvmStatic
    val baseUrl: String
        get() = if (BuildConfig.ISTEST) {
            BASE_URL_4_TEST
        } else BASE_URL

    fun getAuthorization(token: String): String {
        return "bearer $token"
    }

    fun getDataSourceIp(
        selfCashierTerminalConfig: SelfCashierTerminalConfig,
        equType: String
    ): String? {

        if (selfCashierTerminalConfig?.scoRuntimeConfig == null) {
            throw RuntimeException("DataSourceIpUtils SelfCashierTerminalConfig is null")
        }

        val path = "${ApiService.UPLOAD_LOG_FILE}?equType=$equType"
        return if (TextUtils.isEmpty(selfCashierTerminalConfig.scoRuntimeConfig.erpIp)) (baseUrl + path)
        else selfCashierTerminalConfig.scoRuntimeConfig.erpIp + path
    }
}