#include "../Script.hpp"
#include "../UserData/UserDataFunctionType.hpp"

namespace Porygon{
    inline bool ScriptType::CanBeIndexedWith(const ScriptType *) const{
        return false;
    }

    shared_ptr<const ScriptType> ScriptType::GetIndexedType(const ScriptType*) const{
        if (_class == TypeClass::String){
            return make_shared<ScriptType>(TypeClass::String);
        }
        return make_shared<ScriptType>(TypeClass::Error);
    }

    extern "C"{
        ScriptType* CreateScriptType(Porygon::TypeClass t){
            return new ScriptType(t);
        }

        ScriptType* CreateNumericScriptType(bool isAware, bool isFloat){
            return new NumericScriptType(isAware, isFloat);
        }

        ScriptType* CreateStringScriptType(bool knownAtBind, uint32_t hash){
            return new StringScriptType(knownAtBind, hash);
        }

        ScriptType* CreateUserDataFunctionScriptType(ScriptType* returnType, ScriptType* parameters[], size_t parameterCount){
            vector<shared_ptr<ScriptType>> vector(parameterCount);
            for (int i = 0; i < parameterCount; i++){
                vector[i] = shared_ptr<ScriptType>(parameters[i]);
            }
            auto option = new UserData::UserDataFunctionOption(shared_ptr<ScriptType>(returnType), vector);
            auto type = new GenericFunctionScriptType();
            type->RegisterFunctionOption(option);
            return type;
        }
    }
}

