"""Telemetry event schemas."""

from __future__ import annotations

import uuid
from dataclasses import dataclass, field
from datetime import datetime, timezone
from typing import Any


@dataclass
class TelemetryEvent:
    """A telemetry event to be reported to the platform."""

    event_type: str
    data: dict[str, Any]

    # Auto-generated fields
    event_id: str = field(default_factory=lambda: str(uuid.uuid4()))
    timestamp: str = field(
        default_factory=lambda: datetime.now(timezone.utc).isoformat()
    )

    # Set by the client
    package_name: str = ""
    package_version: str = ""
    sdk_version: str = "0.1.0"

    def to_dict(self) -> dict[str, Any]:
        """Convert to dictionary for JSON serialization."""
        return {
            "event_id": self.event_id,
            "event_type": self.event_type,
            "timestamp": self.timestamp,
            "package": self.package_name,
            "package_version": self.package_version,
            "sdk_version": self.sdk_version,
            "data": self.data,
        }


# Common event types
class EventTypes:
    """Standard telemetry event types."""

    # Steer events
    STEER_VECTOR_LOADED = "steer.vector.loaded"
    STEER_VECTOR_APPLIED = "steer.vector.applied"
    STEER_VECTOR_CREATED = "steer.vector.created"

    # Probe/Guardian events
    PROBE_SCAN_COMPLETED = "probe.scan.completed"
    PROBE_SANDBAGGING_DETECTED = "probe.sandbagging.detected"
    PROBE_AWARENESS_CHECKED = "probe.awareness.checked"

    # Eval events
    EVAL_METRIC_COMPUTED = "eval.metric.computed"
    EVAL_SUITE_RUN = "eval.suite.run"

    # Cascade/Orchestrate events
    CASCADE_WORKFLOW_STARTED = "cascade.workflow.started"
    CASCADE_WORKFLOW_COMPLETED = "cascade.workflow.completed"
    CASCADE_STEP_EXECUTED = "cascade.step.executed"

    # Comply/AgentOps events
    COMPLY_RULE_CHECKED = "comply.rule.checked"
    COMPLY_VIOLATION_DETECTED = "comply.violation.detected"

    # Audit events
    AUDIT_TRACE_RECORDED = "audit.trace.recorded"

    # Accel events
    ACCEL_MODEL_PROFILED = "accel.model.profiled"
    ACCEL_OPTIMIZATION_APPLIED = "accel.optimization.applied"
