
class UJavaScriptRuntime {
public:
    virtual void JavaScriptRuntimeCloseComplete() = 0;
    virtual void JavaScriptRuntimeLog(const char * text, bool error) = 0;
};

class IJavaScriptRuntime {
public:
    IJavaScriptRuntime() {}
    virtual ~IJavaScriptRuntime() {}

    virtual void Start() = 0;
    
    virtual void SetAppInstanceStopping() = 0;
    virtual void Close() = 0;
    virtual bool Eval(const char * js, char * result = 0, size_t result_len = 0, const char * filename = 0) = 0;
    virtual void SetArgs(const char * serviceId, const char * serviceDns, const char * instanceName, const char * instanceDomain, const char * instancePassword, const char * serviceVersion, const char * serviceBuild, const char * serviceLabel, const char * dbHost = nullptr) = 0;
    virtual void SetHttpFiles(btree * staticFilesRoot) {}
    virtual void SetJsonApiContext(class JsonApiContext * jsonApiContext) {};
    virtual void AddPbxApiConnection(class IJsonApiConnection * conn, const char * api, const char * domain, const char * pbx, const char * pbxDns, const char * version, const char * build, const char * mode) { }
    virtual void SetDns(class IDns * dns) {};
    virtual void SetSocketProviders(class ISocketProvider * tcpProvider, class ISocketProvider * tlsProvider, class ISocketProvider * udpProvider = 0) {};
    virtual void SetOAuth2Client(class IOAuth2Client * oauth2Client) {}
    virtual void SetSmtpProvider(class ISmtpProvider * smtpProvider) {}
    virtual void SetWebserverPlugin(class IWebserverPlugin * webserverPlugin) {}
    virtual void SetWebserverUrl(const char * url) {}
    virtual void SetDatabase(class IDatabase * database) {}
    virtual void SetConfigContext(class ConfigContext * configContext, std::list<class ConfigItem *> * configItems) {}
    virtual void ConfigChanged() {}
};

extern "C" IJavaScriptRuntime * CreateJavaScriptRuntime(UJavaScriptRuntime * user, IIoMux * iomux, IInstanceLog * log);
extern void AddJavaScriptModuleTimers();
extern void AddJavaScriptModuleJsonApis();
extern void AddJavaScriptModulePbxApis();
extern void AddJavaScriptModuleHttpClient();
extern void AddJavaScriptModuleWebServer();
extern void AddJavaScriptModuleDatabase();
extern void AddJavaScriptModuleConfig();
extern void AddJavaScriptModuleWebsocketClient();
extern void AddJavaScriptModuleAppWebsocketClient();
extern void AddJavaScriptModuleDns();
extern void AddJavaScriptModuleCrypto();
extern void AddJavaScriptModuleNetwork();
extern void AddJavaScriptModuleSandbox();
extern void AddJavaScriptModuleAppInstance();
extern void AddJavaScriptModuleFileSystem();
extern void AddJavaScriptModuleSmtpClient();
