#pragma once

#include <map>
#include <optional>
#include <string>

#include "vec.hpp"
#include "wren.hpp"

namespace wren {
    struct entvars {
        int id{-1};
        math::vec3f origin{};
        float next_think{0.0f};
        int spawn_flags{0};
        bool free{false};
        math::vec3f velocity{};
        math::vec3f angles{};
        math::vec3f mins{};
        math::vec3f maxs{};
        std::string class_name{};
        std::string target_name{};
        float sounds{0};
        std::string noise{};
        std::string noise1{};
        std::string noise2{};
        std::string noise3{};
    };

    enum class typing {
        UNDEFINED = -1,
        INT = 1,
        FLOAT = 2,
        VECTOR = 3,
        STRING = 4
    };

    void init();
    void load_progs();

    std::optional<std::pair<int, WrenHandle*>> create_entity(const std::string &classname, std::map<std::string, std::string> pairs);
    void run_think(int index);
    void set_field(WrenHandle *ent, std::string key, std::string value);
    std::map<std::string, std::string> parse_fields(std::istringstream &ss);
}
