// Generated telemetry code module
//
// This module contains code generated by Weaver from semantic convention schemas.
// DO NOT EDIT files in this directory manually - they will be overwritten.
//
// To regenerate:
// ```bash
// weaver registry generate rust \
//   --registry registry/ \
//   --templates templates/registry/rust/ \
//   --output crates/clnrm-core/src/telemetry/generated/
// ```

// Placeholder spans module - will be replaced by weaver generation
pub mod spans {
    use tracing::{span, Level, Span};

    // Placeholder - will be generated from schemas
    #[derive(Debug)]
    pub struct TestExecutionSpan {
        span: Span,
    }

    impl TestExecutionSpan {
        pub fn new(test_name: &str, container_image: &str) -> Self {
            let span = span!(
                Level::INFO,
                "test.execution",
                test.name = %test_name,
                container.image = %container_image,
            );
            Self { span }
        }

        pub fn set_isolated(&self, value: bool) -> &Self {
            self.span.record("test.isolated", value);
            self
        }

        pub fn set_result(&self, value: &str) -> &Self {
            self.span.record("test.result", value);
            self
        }

        pub fn enter(&self) -> tracing::span::Entered<'_> {
            self.span.enter()
        }

        pub fn span(&self) -> &Span {
            &self.span
        }

        pub fn end(self) {
            drop(self.span);
        }
    }
}

// Placeholder metrics module - will be replaced by weaver generation
#[cfg(feature = "otel-metrics")]
pub mod metrics {
    use opentelemetry::metrics::{Histogram, Meter};

    // Placeholder - will be generated from schemas
    #[derive(Debug, Clone)]
    pub struct TestExecutionMetric {
        histogram: Histogram<f64>,
    }

    impl TestExecutionMetric {
        pub fn new(meter: &Meter) -> Self {
            let histogram = meter
                .f64_histogram("test.execution.duration")
                .with_description("Test execution duration in milliseconds")
                .with_unit("ms")
                .build();
            Self { histogram }
        }

        pub fn record(&self, value: f64, test_name: &str, result: &str) {
            use opentelemetry::KeyValue;
            self.histogram.record(
                value,
                &[
                    KeyValue::new("test.name", test_name.to_string()),
                    KeyValue::new("test.result", result.to_string()),
                ],
            );
        }
    }
}

#[cfg(not(feature = "otel-metrics"))]
pub mod metrics {
    // No-op metrics when feature is disabled
    #[derive(Debug, Clone)]
    pub struct TestExecutionMetric;

    impl TestExecutionMetric {
        pub fn new(_meter: &()) -> Self {
            Self
        }

        pub fn record(&self, _value: f64, _test_name: &str, _result: &str) {}
    }
}

// Placeholder mocks module - will be replaced by weaver generation
#[cfg(test)]
pub mod mocks {
    use mockall::automock;

    #[automock]
    pub trait TestExecutionSpanTrait: Send + Sync {
        fn set_isolated(&self, value: bool);
        fn set_result(&self, value: String);
        fn enter(&self);
        fn end(self: Box<Self>);
    }

    #[automock]
    pub trait TestExecutionMetricTrait: Send + Sync {
        fn record(&self, value: f64, test_name: String, result: String);
    }
}

// Placeholder events module - will be replaced by weaver generation
pub mod events {
    use tracing::{event, Level};

    pub struct TestStartedEvent;

    impl TestStartedEvent {
        pub fn emit(test_name: &str, container_image: &str) {
            event!(
                Level::INFO,
                test.name = %test_name,
                container.image = %container_image,
                "test.started"
            );
        }
    }

    pub struct TestCompletedEvent;

    impl TestCompletedEvent {
        pub fn emit(test_name: &str, result: &str, duration_ms: f64) {
            event!(
                Level::INFO,
                test.name = %test_name,
                test.result = %result,
                test.duration_ms = duration_ms,
                "test.completed"
            );
        }
    }
}
