import { ConfigLoader } from 'loadson'
import { RPCExporter } from 'rpclibrary'

export type ConfigLoaderIfc<ConfT> = {
    Config : {
        getConfig: () => ConfT
        resetConfig: () => ConfT
        setConfig: (conf:ConfT) => ConfT
        setConfigKey: (key:string, value:any) => ConfT
        deleteConfigKey: (key:string) => ConfT
        getConfigKey: (key:string) => any
    }
}

export class RPCConfigLoader<ConfT> 
extends ConfigLoader<ConfT>
implements RPCExporter<ConfigLoaderIfc<ConfT>, "Config">{

    name = "Config" as "Config"

    exportRPCs() {
        return [{
            name: "getConfig" as "getConfig",
            call: () => { return this.getConfig() }
        },{
            name: "resetConfig" as "resetConfig",
            call: () => { return this.resetConfig() }
        },{
            name: "setConfig" as "setConfig",
            call: (conf:ConfT) => { return this.setConfig(conf) }
        },{
            name: "setConfigKey" as "setConfigKey",
            call: (key:string, value:any) => { return this.setConfigKey(key, value) }
        },{
            name: "deleteConfigKey" as "deleteConfigKey",
            call: (key:string) => { return this.deleteConfigKey(key) }
        },{
            name: "getConfigKey" as "getConfigKey",
            call: (key:string) => { return this.getConfigKey(key) }
        }]
    }
}