package com.adealink.weparty.webview.jsbridge.manager

import com.adealink.weparty.webview.jsbridge.config.IJSBridgeConfig

fun initJSBridgeManager(initiator: (() -> JSBridgeManager)) {
    JSBridgeManager.initiator = initiator
}

@Synchronized
fun createJSBridgeManager(config: IJSBridgeConfig): JSBridgeManager {
    return JSBridgeManager(config)
}

class JSBridgeManager(val config: IJSBridgeConfig) : IJSBridgeManager {

    companion object {

        var initiator: (() -> JSBridgeManager)? = null

        val instance: IJSBridgeManager by lazy { initiator!!() }

    }

    override fun addWhiteList(hosts: List<String>) {
        config.addWhiteList(hosts)
    }

    override fun addBlackList(hosts: List<String>) {
        config.addBlackList(hosts)
    }

    override fun isWhite(url: String): Boolean {
        return config.isWhite(url)
    }

    override fun isBlack(url: String): Boolean {
        return config.isBlack(url)
    }

}