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

namespace lsp::provider::text_document
{

    std::string DidClose::GetMethod() const
    {
        return "textDocument/didClose";
    }

    std::string DidClose::GetProviderName() const
    {
        return "TextDocumentDidClose";
    }

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

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

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

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

}
