#pragma once

#include <cstddef>
#include <string>
#include <string_view>
#include <unordered_map>
#include <vector>

#include "adapters/eft/common/EftMongoId.h"
#include "adapters/il2cpp/Il2CppObjectInstance.h"

struct Il2CppObject;

namespace ta::adapters::eft::quests
{
    struct QuestConditionNode
    {
        ta::adapters::eft::common::EftMongoId id{};
        std::string id_string;
        std::string text;
        std::string target_template_id;
        Il2CppObject* condition = nullptr;
        Il2CppObject* counter = nullptr;
        int current = 0;
        int target = 0;
        int depth = 0;
        bool completed = false;
        bool counter_root = false;
        std::vector<std::size_t> children;
    };

    class QuestConditionGraph final
    {
    public:
        static QuestConditionGraph build(
            ta::adapters::il2cpp::Il2CppObjectInstance& quest,
            ta::adapters::il2cpp::Il2CppObjectInstance main_player);

        [[nodiscard]] const std::vector<QuestConditionNode>& nodes() const noexcept;
        [[nodiscard]] std::vector<QuestConditionNode>& nodes() noexcept;
        [[nodiscard]] const QuestConditionNode* find(std::string_view id) const noexcept;

    private:
        std::vector<QuestConditionNode> nodes_;
        std::unordered_map<std::string, std::size_t> index_by_id_;
    };
}
