#pragma once

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

#include "adapters/eft/items/catalog/ItemTemplateReader.h"
#include "features/items/contracts/ItemCatalogTypes.h"

namespace ta::adapters::eft::items
{
    class CatalogIndexBuilder final
    {
    public:
        void reset(std::size_t expected_count);
        void append(ItemTemplateRecord record);
        bool localize_batch(std::size_t& index, std::size_t batch_size);
        void finalize();

        [[nodiscard]] const std::vector<ta::features::items::contracts::ItemCatalogEntry>& entries() const noexcept;
        [[nodiscard]] ta::features::items::contracts::ItemCategory category_for(std::string_view id) const;
        [[nodiscard]] int max_stack_for(std::string_view id) const noexcept;

    private:
        struct PendingLocalization
        {
            std::string type_name;
        };

        std::vector<PendingLocalization> pending_;
        std::vector<ta::features::items::contracts::ItemCatalogEntry> entries_;
        std::unordered_map<std::string, ta::features::items::contracts::ItemCategory> category_by_id_;
        std::unordered_map<std::string, int> max_stack_by_id_;
        std::unordered_set<std::string> seen_ids_;
    };
}
