#pragma once
#include <shared_mutex>
#include <unordered_map>
#include "../types.hpp"
#include "../../../../language/symbol/table.hpp"

namespace lsp::service::symbol::repository
{
    class Editing
    {
    public:
        Editing() = default;
        ~Editing() = default;

        Editing(const Editing&) = delete;
        Editing& operator=(const Editing&) = delete;

        // ==================== 基础CRUD ====================
        void AddOrUpdate(EditingSymbolTable table);
        void Remove(const protocol::DocumentUri& uri);
        bool Contains(const protocol::DocumentUri& uri) const;
        void Clear();
        size_t Count() const;

        const language::symbol::SymbolTable* GetSymbolTable(const protocol::DocumentUri& uri) const;

        std::optional<TsfFileType> GetFileType(const protocol::DocumentUri& uri) const;
        std::optional<protocol::integer> GetVersion(const protocol::DocumentUri& uri) const;

    private:
        mutable std::shared_mutex mutex_;
        std::unordered_map<protocol::DocumentUri, EditingSymbolTable> documents_;
    };
}
