"""ScenarioMetric model."""

import uuid
from sqlalchemy import Column, String, DECIMAL, DateTime, ForeignKey
from sqlalchemy.dialects.postgresql import UUID, JSONB
from sqlalchemy.orm import relationship

from src.models.base import Base


class ScenarioMetric(Base):
    """Metric time-series model for scenario analytics."""

    __tablename__ = "scenario_metrics"

    id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
    scenario_id = Column(
        UUID(as_uuid=True),
        ForeignKey("scenarios.id", ondelete="CASCADE"),
        nullable=False,
    )
    timestamp = Column(DateTime(timezone=True), nullable=False)
    metric_type = Column(
        String(50), nullable=False
    )  # 'sqs', 'lambda', 'bedrock', 'safety'
    metric_name = Column(String(100), nullable=False)
    value = Column(DECIMAL(15, 6), default=0.0, nullable=False)
    unit = Column(String(20), nullable=False)  # 'count', 'bytes', 'tokens', 'usd'
    extra_data = Column(JSONB, default=dict)

    # Relationships
    scenario = relationship("Scenario", back_populates="metrics")
