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 = () => [
        this.getConfig,
        this.resetConfig,
        this.setConfig,
        this.setConfigKey,
        this.deleteConfigKey,
        this.getConfigKey
    ]
}