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: this.getConfig
        },{
            name: "resetConfig" as "resetConfig",
            call: this.resetConfig
        },{
            name: "setConfig" as "setConfig",
            call: this.setConfig
        },{
            name: "setConfigKey" as "setConfigKey",
            call: this.setConfigKey
        },{
            name: "deleteConfigKey" as "deleteConfigKey",
            call: this.deleteConfigKey
        },{
            name: "getConfigKey" as "getConfigKey",
            call: this.getConfigKey
        }]
    }
}