#ifndef ECS_QUESTMODULE_H
#define ECS_QUESTMODULE_H

#include <flecs.h>
#include <Ogre.h>
#include <lua.hpp>

namespace ECS {

struct QuestModule
{
    struct Quest {
        enum {OK = 0, BUSY, ERROR};
    private:
        virtual void activate() = 0;
        virtual int update(float delta) = 0;
        virtual void finish(int ret) = 0;
        virtual void event(const std::string &evt) = 0;
        virtual bool _can_activate() {return true;};
    protected:
        std::string name;
        bool active;
        bool complete;
        float updatePeriod;
        float timeAcc;
        void _activate();
        void _finish(int ret);
    public:
        Quest(const std::string &name);
        virtual ~Quest();
        int _update(float delta);
        void _event(const std::string &evt);
        bool _is_active() {return active;}
        bool _is_complete() {return complete;}
    };
    std::set<Quest *> quests;
    flecs::entity quest_update;
public:
    QuestModule(flecs::world &ecs);
    void addQuest(Quest *quest);
    void removeQuest(Quest *quest);
    void addLuaQuest(lua_State *L);
};

} // namespace ECS

#endif // ECS_QUESTMODULE_H
