using System;
using System.Collections.Generic;

namespace EonaCat.LogStack.Telemetry;

/// <summary>
/// OpenTelemetry inspired span representation.
/// Supports distributed tracing concepts without requiring external dependencies.
/// </summary>
public sealed class TelemetrySpan
{
    public string TraceId { get; set; } = Guid.NewGuid().ToString("N");
    public string SpanId { get; set; } = System.Guid.NewGuid().ToString("N").Substring(0, 16);
    public string? ParentSpanId { get; set; }
    public string Name { get; set; } = "";
    public string Kind { get; set; } = "internal";
    public DateTimeOffset StartTime { get; set; } = DateTimeOffset.UtcNow;
    public double DurationMs { get; set; }
    public string Status { get; set; } = "Unset";
    public Dictionary<string, string> Attributes { get; } = new();
    public List<TelemetryEvent> Events { get; } = new();

    public TelemetryEvent ToEvent() => new()
    {
        Name = Name,
        TraceId = TraceId,
        DurationMs = DurationMs,
        Tags = Attributes
    };
}
