
#ifndef PORYGONLANG_USERDATAFIELD_HPP
#define PORYGONLANG_USERDATAFIELD_HPP


#include "../Evaluator/EvalValues/EvalValue.hpp"
#include "../Evaluator/EvalValues/NumericEvalValue.hpp"

namespace Porygon::UserData{
    class UserDataField {
        shared_ptr<const ScriptType> _type;
        const Evaluation::EvalValue* (*_get)(void* obj);
        void (*_set)(void* obj, const Evaluation::EvalValue* val);
    public:
        UserDataField(const ScriptType* type, const Evaluation::EvalValue* (*getter)(void* obj), void (*setter)(void* obj, const Evaluation::EvalValue* val))
            : _type(shared_ptr<const ScriptType>(type)), _get(getter), _set(setter){
        }

        [[nodiscard]]
        inline shared_ptr<const ScriptType> GetType(){
            return _type;
        }

        [[nodiscard]]
        inline bool HasGetter(){
            return _get != nullptr;
        }

        [[nodiscard]]
        inline const Evaluation::EvalValue* Get(void* obj){
            return this ->_get(obj);
        }

        [[nodiscard]]
        inline bool HasSetter(){
            return _set != nullptr;
        }

        inline void Set(void* obj, const Evaluation::EvalValue* val){
            this->_set(obj, val);
        }
    };
}


#endif //PORYGONLANG_USERDATAFIELD_HPP
