#pragma once

#include <string>
#include <unordered_set>

#include "adapters/il2cpp/Il2CppObjectInstance.h"
#include "features/items/contracts/WishlistSnapshot.h"

namespace ta::adapters::eft::common
{
    enum class LootKind : char
    {
        Normal,
        Wishlist,
        Quest,
        Corpse,
        Container
    };

    struct QuestLootIndex
    {
        std::unordered_set<Il2CppObject*> objects;
        std::unordered_set<std::string> template_ids;

        bool contains(Il2CppObject* object, const std::string& template_id) const
        {
            return (object && objects.contains(object)) ||
                   (!template_id.empty() && template_ids.contains(template_id));
        }
    };

    class LootClassifier
    {
    public:
        static bool looks_like_corpse(Il2CppObject* object);
        static bool looks_like_default_inventory(Il2CppObject* object);
        static bool looks_like_container(Il2CppObject* object);

        static Il2CppObject* get_item_object(Il2CppObject* loot_object);
        static std::string get_template_id_from_item(Il2CppObject* item);
        static std::string get_loot_template_id(Il2CppObject* loot_object);

        static bool is_quest_item(Il2CppObject* item_object);
        static bool is_quest_item(Il2CppObject* loot_object, Il2CppObject* item_object);

        static LootKind classify_loot_item(
            Il2CppObject* item_object,
            const ta::features::items::contracts::WishlistSnapshot& wishlist,
            const std::string& template_id);

        static LootKind classify_loot_item(
            Il2CppObject* loot_object,
            Il2CppObject* item_object,
            const ta::features::items::contracts::WishlistSnapshot& wishlist,
            const std::string& template_id);
    };

    QuestLootIndex collect_quest_loot_index(
        ta::adapters::il2cpp::Il2CppObjectInstance game_world_instance);
}
