#include <spdlog/spdlog.h>
#include "./shutdown.hpp"
#include "../../protocol/transform/facade.hpp"

namespace lsp::provider
{
    std::string Shutdown::GetMethod() const
    {
        return "shutdown";
    }

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

    std::string Shutdown::ProvideResponse(const protocol::RequestMessage& request, ExecutionContext& context)
    {
        spdlog::debug("ShutdownProvider: Providing response for method {}", request.method);

        // 触发关闭事件
        context.TriggerLifecycleEvent(ServerLifecycleEvent::kShuttingDown);

        // 构建响应 - shutdown 返回 null
        protocol::ResponseMessage response;
        response.id = request.id;
        auto json = transform::Serialize(response);
        if (!json.has_value())
            return BuildErrorResponseMessage(request, protocol::ErrorCodes::InternalError, "Failed to serialize response");
        spdlog::info("Shutdown request processed successfully");
        return json.value();
    }

}
