"""SQLAlchemy model for the techniques table."""

# Import uuid
import uuid

# Import Boolean, Column, DateTime, Enum, String, Text from sqlalchemy
from sqlalchemy import Boolean, Column, DateTime, Enum, String, Text

# Import JSONB, UUID from sqlalchemy.dialects.postgresql
from sqlalchemy.dialects.postgresql import JSONB, UUID

# Import relationship from sqlalchemy.orm
from sqlalchemy.orm import relationship

# Import Base from app.database
from app.database import Base

# Import TechniqueStatus from app.models.enums
from app.models.enums import TechniqueStatus


# Define class Technique
class Technique(Base):
    """MITRE ATT&CK Technique model.

    Represents an attack technique from the MITRE ATT&CK framework,
    including its coverage status and associated tests.
    """
    # Assign __tablename__ = "techniques"
    __tablename__ = "techniques"

    # Assign id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
    id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
    # Assign mitre_id = Column(String, unique=True, nullable=False)  # e.g., "T1059.001"
    mitre_id = Column(String, unique=True, nullable=False)  # e.g., "T1059.001"
    # Assign name = Column(String, nullable=False)
    name = Column(String, nullable=False)
    # Assign description = Column(Text, nullable=True)
    description = Column(Text, nullable=True)
    # Assign tactic = Column(String, nullable=True)
    tactic = Column(String, nullable=True)
    # Assign platforms = Column(JSONB, nullable=True, default=[])
    platforms = Column(JSONB, nullable=True, default=[])
    # Assign mitre_version = Column(String, nullable=True)
    mitre_version = Column(String, nullable=True)
    # Assign mitre_last_modified = Column(DateTime, nullable=True)
    mitre_last_modified = Column(DateTime, nullable=True)
    # Assign is_subtechnique = Column(Boolean, default=False)
    is_subtechnique = Column(Boolean, default=False)
    # Assign parent_mitre_id = Column(String, nullable=True)
    parent_mitre_id = Column(String, nullable=True)
    # Assign status_global = Column(
    status_global = Column(
        Enum(TechniqueStatus, name="techniquestatus"),
        # Keyword argument: default
        default=TechniqueStatus.not_evaluated
    )
    # Assign review_required = Column(Boolean, default=False)
    review_required = Column(Boolean, default=False)
    # Assign last_review_date = Column(DateTime, nullable=True)
    last_review_date = Column(DateTime, nullable=True)
    # Assign external_references = Column(JSONB, nullable=True, default=list)
    external_references = Column(JSONB, nullable=True, default=list)

    # Relationships
    tests = relationship("Test", back_populates="technique")
