/*
 * SPDX-FileCopyrightText: 2025 Copyright contributors to the cppTango project
 *
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */
#ifndef TANGO_INTERNAL_TELEMETRY_SPANIMPLEMENTATION_H
#define TANGO_INTERNAL_TELEMETRY_SPANIMPLEMENTATION_H

#include <tango/common/telemetry/Span.h>

#include <opentelemetry/trace/span.h>
#include <opentelemetry/trace/span_context.h>

namespace Tango::telemetry
{

//---------------------------------------------------------------------------------------------------------------------
// The opaque implementation classes.
//
// Such classes are usually inner classes of their associated public class but, due to a technical constraint we have
// here on one of them, we decide, for all of them, to put their respective forward declaration here.
//---------------------------------------------------------------------------------------------------------------------
class SpanImplementation final
{
  public:
    // the actual/concrete opentelemetry span
    opentelemetry::nostd::shared_ptr<opentelemetry::trace::Span> otel_span;

    // the Span status (no way to retrieve the current status on the otel. span)
    Span::Status span_status{Span::Status::kUnset};

    //-------------------------------------------------------------------------------------
    // SpanImplementation::SpanImplementation
    //-------------------------------------------------------------------------------------
    explicit SpanImplementation(opentelemetry::nostd::shared_ptr<opentelemetry::trace::Span> span) :
        otel_span(std::move(span))
    {
    }

    opentelemetry::trace::Span &opentelemetry_span() noexcept;

    void set_attribute(const std::string &key, const AttributeValue &value) noexcept;

    void add_event(const std::string &name, const Attributes &attributes) noexcept;

    void set_status(const Span::Status &status, const std::string &description = "") noexcept;

    Span::Status get_status() const noexcept;

    void end() noexcept;

    bool is_recording() const noexcept;
};

} // namespace Tango::telemetry

#endif // TANGO_INTERNAL_TELEMETRY_SPANIMPLEMENTATION_H
