#pragma once

#include <shared_mutex>
#include <unordered_map>
#include <optional>
#include "../../../../utils/string.hpp"
#include "../types.hpp"

namespace lsp::service::symbol::repository
{
    /**
     * 系统符号仓库
     *
     * 职责：
     * - 存储标准库、系统库的符号索引
     * - 提供只读的快速查询接口
     * - 支持分类索引（category）
     */
    class System
    {
    public:
        System() = default;
        ~System() = default;
        System(const System&) = delete;
        System& operator=(const System&) = delete;

        // ==================== 基础操作 ====================
        void Add(SystemSymbolIndex index);
        size_t Count() const;
        void Clear();

        // ==================== 查找API ====================
        std::optional<SystemSymbolIndex> FindUnit(const std::string& name) const;
        std::optional<SystemSymbolIndex> FindClass(const std::string& name) const;
        std::optional<SystemSymbolIndex> FindFunction(const std::string& name) const;

        // ==================== 列表API ====================
        std::vector<SystemSymbolIndex> Units() const;
        std::vector<SystemSymbolIndex> Classes() const;
        std::vector<SystemSymbolIndex> Functions() const;

    private:
        mutable std::shared_mutex mutex_;
        std::unordered_map<std::string, SystemSymbolIndex, utils::IHasher, utils::IEqualTo> units_;
        std::unordered_map<std::string, SystemSymbolIndex, utils::IHasher, utils::IEqualTo> classes_;
        std::unordered_map<std::string, SystemSymbolIndex, utils::IHasher, utils::IEqualTo> functions_;
    };
}
