package co.id.datacomsolusindo.ipphonebridge

import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
import org.ini4j.Wini
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.scheduling.annotation.EnableScheduling
import java.io.File
import java.io.Serializable
import java.util.*


@SpringBootApplication
@EnableScheduling
class IpPhoneBridgeApplication

fun main(args: Array<String>) {
    TimeZone.setDefault(TimeZone.getTimeZone("Asia/Jakarta"))
    val sApp = SpringApplication(IpPhoneBridgeApplication::class.java)

    sApp.setDefaultProperties(Singletons.properties())
    sApp.run(*args)
    //Configurator.reconfigure(URI("http://127.0.0.1:9090/log-setting.xml"))
    LogManager.getLogger("co.id.datacomsolusindo.ipphonebridge.IpPhoneBridgeApplication").info("Bridge Start")
    println("hostname ${System.getenv("HOSTNAME")}")
    println("token ${System.getenv("KUBE_TOKEN")}")
    println("service_host ${System.getenv("KUBERNETES_SERVICE_HOST")}")
    println("port ${System.getenv("KUBERNETES_PORT_443_TCP_PORT")}")

//    val command =
//        "curl -X GET https://${System.getenv("KUBERNETES_SERVICE_HOST")}:${System.getenv("KUBERNETES_PORT_443_TCP_PORT")}/api/v1/namespaces/tm-bridge/pods/${
//            System.getenv("HOSTNAME")
//        }"

}

class Client(
    val number: String,
    var connectAt: String,
    var lastRequest: String,
    val sessionId: String?
) : Serializable {
    var reqSuccess = 0
    var reqFailed = 0
    var avgReqSuccessTime = 0.0
}

object AppLog {
    fun write(cls: Class<*>): Logger {
        return LogManager.getLogger(cls)
    }
}


