#ifndef PORYGONLANG_SCRIPTOPTIONS_HPP
#define PORYGONLANG_SCRIPTOPTIONS_HPP

#include <string>
#include <utility>
namespace Porygon{
    class Script;

    class ScriptOptions{
        static Porygon::ScriptOptions DefaultScriptOptions;
        static void DefaultPrint(const char16_t* s);
        static bool DefaultModuleExists(const std::string& moduleName);
        static Script* DefaultResolveModule(const std::string& moduleName);

        void (*_print)(const char16_t* s) = DefaultPrint;
        bool (*_doesModuleExist)(const std::string& moduleName) = DefaultModuleExists;
        Script* (*_resolveModule)(const std::string& moduleName) = DefaultResolveModule;
        static std::streambuf* _printBuffer;
        static std::ostream* _printStream;

    public:
        static Porygon::ScriptOptions* GetDefaultScriptOptions(){
            return &DefaultScriptOptions;
        }


        inline void Print(const char16_t* s) const{
            this -> _print(s);
        }

        inline bool DoesModuleExist(std::string moduleName) const{
            return _doesModuleExist(std::move(moduleName));
        }

        inline Script* ResolveModule(std::string moduleName) const{
            return _resolveModule(std::move(moduleName));
        }

        void SetPrintFunc(void (*print)(const char16_t *)){
            this -> _print = print;
        }

        void SetModuleExistsFunc(bool (*doesModuleExist)(const std::string& moduleName)){
            this ->_doesModuleExist = doesModuleExist;
        }

        void SetResolveModuleFunc(Script* (*resolveModule)(const std::string& moduleName)){
            this ->_resolveModule = resolveModule;
        }

        std::ostream& GetPrintStream(){
            return *Porygon::ScriptOptions::_printStream;
        }

        void SetPrintStream(std::ostream* stream){
            delete ScriptOptions::_printStream;
            ScriptOptions::_printStream = stream;
        }
    };
}

#endif //PORYGONLANG_SCRIPTOPTIONS_HPP
