#include <spdlog/spdlog.h>
#include "./did_change.hpp"
#include "../../protocol/transform/facade.hpp"
#include "../../service/document.hpp"

namespace lsp::provider::text_document
{

    std::string DidChange::GetMethod() const
    {
        return "textDocument/didChange";
    }

    std::string DidChange::GetProviderName() const
    {
        return "TextDocumentDidChange";
    }

    void DidChange::HandleNotification(const protocol::NotificationMessage& notification, ExecutionContext& context)
    {
        spdlog::debug("TextDocumentDidChangeProvider: Providing response for method {}", notification.method);

        protocol::DidChangeTextDocumentParams params = transform::As<protocol::DidChangeTextDocumentParams>(notification.params.value());

        auto document_service = context.GetService<service::Document>();
        document_service->UpdateDocument(params);

        spdlog::info("Document updated: {}", params.textDocument.uri);
    }

}
