"""ScenarioLog model."""

import uuid
from sqlalchemy import Column, String, Integer, Boolean, DateTime, ForeignKey
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import relationship

from src.models.base import Base


class ScenarioLog(Base):
    """Log entry model for received logs."""

    __tablename__ = "scenario_logs"

    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,
    )
    received_at = Column(DateTime(timezone=True), nullable=False)
    message_hash = Column(String(64), nullable=False, index=True)
    message_preview = Column(String(500), nullable=True)
    source = Column(String(100), default="unknown", nullable=False)
    size_bytes = Column(Integer, default=0, nullable=False)
    has_pii = Column(Boolean, default=False, nullable=False)
    token_count = Column(Integer, default=0, nullable=False)
    sqs_blocks = Column(Integer, default=1, nullable=False)

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