"""SQLAlchemy model for the evidence table."""

# Import uuid
import uuid

# Import Column, DateTime, Enum, ForeignKey, String, Tex... from sqlalchemy
from sqlalchemy import Column, DateTime, Enum, ForeignKey, String, Text, func

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

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

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

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


# Define class Evidence
class Evidence(Base):
    """Evidence model for storing file metadata associated with tests.

    Files are stored in MinIO, and this model tracks the file location,
    integrity hash, and upload metadata.

    The ``team`` field distinguishes whether this evidence was uploaded by
    Red Team (attack evidence) or Blue Team (detection evidence).
    """
    # Assign __tablename__ = "evidences"
    __tablename__ = "evidences"

    # 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 test_id = Column(UUID(as_uuid=True), ForeignKey("tests.id"), nullable=False)
    test_id = Column(UUID(as_uuid=True), ForeignKey("tests.id"), nullable=False)
    # Assign file_name = Column(String, nullable=False)
    file_name = Column(String, nullable=False)
    # Assign file_path = Column(String, nullable=False)  # Path in MinIO
    file_path = Column(String, nullable=False)  # Path in MinIO
    # Assign sha256_hash = Column(String, nullable=False)
    sha256_hash = Column(String, nullable=False)
    # Assign uploaded_by = Column(UUID(as_uuid=True), ForeignKey("users.id"), nullable=True)
    uploaded_by = Column(UUID(as_uuid=True), ForeignKey("users.id"), nullable=True)
    # Assign uploaded_at = Column(DateTime(timezone=True), server_default=func.now())
    uploaded_at = Column(DateTime(timezone=True), server_default=func.now())
    # Assign team = Column(Enum(TeamSide, name="teamside"), nullable=False, default=Tea...
    team = Column(Enum(TeamSide, name="teamside"), nullable=False, default=TeamSide.red)
    # Assign notes = Column(Text, nullable=True)
    notes = Column(Text, nullable=True)
    # Assign data_classification = Column(String(20), nullable=False, server_default="internal")
    data_classification = Column(String(20), nullable=False, server_default="confidential")

    # Relationships
    test = relationship("Test", back_populates="evidences")
    # Assign uploader = relationship("User", foreign_keys=[uploaded_by])
    uploader = relationship("User", foreign_keys=[uploaded_by])
