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


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>[]
}