#pragma once

#include "graphics/model.hpp"
#include "script.hpp"
#include "utils/ptr.hpp"

#include <vector>
#include <algorithm>    // for_each


namespace frog
{


class engine;
struct script;


class game_object
{
    gl::model _model;

    bool _destroyed = false;

    std::vector<ptr<script>> scripts;

    template<typename Func>
    void for_each_script(Func func)
    {
        std::for_each(scripts.begin(), scripts.end(), [&](auto& ptr)
            {
                assert(ptr);
                func(*ptr);
            });
    }

public:
    game_object() = default;

    script* add_script(ptr<script> script);

    bool remove_script(script* scr);

    void init(engine& engine);

    void stable_update(engine& engine);

    void frame_update(engine& engine);

    void destroyed(engine& engine);

    void destroy() { _destroyed = true; }

    bool is_destroyed() { return _destroyed; }

    const gl::model& model() const { return _model; }
          gl::model& model()       { return _model; }
};


} // namespace frog
