import { FrontworkAdmin } from "./Admin"
import { RPC, RPCExporter } from "rpclibrary"
import { TableDefiniton } from "./Types"
import { TableDefinitionExporter } from "./Interfaces"
import { ConfigExporter } from "loadson"

export abstract class Plugin<ConfType = {}> 
implements ConfigExporter<ConfType>, RPCExporter<any,any,any>, TableDefinitionExporter{
    
    constructor (protected admin: FrontworkAdmin, public name:string){
        if(!this.getConfig()){
            this.setConfig(this.getDefaultConfig())
        }
    }
    public setConfig = (conf:ConfType) => this.admin.setConfigKey(this.name, conf) 
    public getConfig = () => this.admin.getConfigKey(this.name) 

    abstract getTableDefinitions(): TableDefiniton[]
    abstract getDefaultConfig(): ConfType
    abstract exportRPCs(): RPC<any,any>[]
}