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

namespace lsp::provider::client
{
    std::string RegisterCapability::GetMethod() const
    {
        return "client/registerCapability";
    }

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

    std::string RegisterCapability::ProvideResponse(const protocol::RequestMessage& request, ExecutionContext& context)
    {
        static_cast<void>(context);
        spdlog::debug("RegisterCapabilityProvider: Providing response for method {}", request.method);
        // 这个方法通常不会被调用，因为这是服务器发起的请求
        // 但为了完整性还是实现它

        protocol::ResponseMessage response;
        response.id = request.id;
        response.result = std::nullopt; // 成功返回null

        std::optional<std::string> json = transform::Serialize(response);
        if (!json.has_value())
            return BuildErrorResponseMessage(request, protocol::ErrorCodes::InternalError, "Internal error");
        return json.value();
    }
}
