"""Scenario model."""

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

from src.models.base import Base, TimestampMixin


class Scenario(Base, TimestampMixin):
    """Scenario model for cost simulation."""

    __tablename__ = "scenarios"

    id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
    name = Column(String(255), nullable=False)
    description = Column(Text, nullable=True)
    tags = Column(JSONB, default=list)
    status = Column(
        Enum("draft", "running", "completed", "archived", name="scenario_status"),
        nullable=False,
        default="draft",
    )
    region = Column(String(50), nullable=False, default="us-east-1")
    completed_at = Column(DateTime(timezone=True), nullable=True)
    started_at = Column(DateTime(timezone=True), nullable=True)
    total_requests = Column(Integer, default=0, nullable=False)
    total_cost_estimate = Column(DECIMAL(12, 6), default=0.0, nullable=False)

    # Relationships
    logs = relationship(
        "ScenarioLog", back_populates="scenario", cascade="all, delete-orphan"
    )
    metrics = relationship(
        "ScenarioMetric", back_populates="scenario", cascade="all, delete-orphan"
    )
    reports = relationship(
        "Report", back_populates="scenario", cascade="all, delete-orphan"
    )
