#include "./interface.hpp"
#include "../../protocol/transform/facade.hpp"

namespace lsp::provider
{

    std::string BuildErrorResponseMessage(const protocol::RequestMessage& request, protocol::ErrorCodes code, const std::string& message)
    {
        protocol::ResponseMessage response;
        response.id = request.id;
        protocol::ResponseError error;
        error.code = code;
        error.message = message;
        response.error = error;
        std::optional<std::string> json = transform::Serialize(response);
        if (json.has_value())
            return json.value();
        spdlog::error("Failed to serialize error response.");
        return R"({"jsonrpc":"2.0","id":null,"error":{"code":-32603,"message":"Failed to serialize error response"}})";
    }

}
