#include "./provider_interface.hpp"

namespace lsp::providers
{

    std::string IRequestProvider::BuildErrorResponseMessage(const protocol::RequestMessage& request, protocol::ErrorCode 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::string json;
        auto ec = glz::write_json(error, json);
        if (ec)
        {
            spdlog::error("Failed to serialize error response: {}", glz::format_error(ec, json));
            return R"({"jsonrpc":"2.0","id":null,"error":{"code":-32603,"message":"Failed to serialize error response"}})";
        }
        return json;
    }

}
