# #region DatasetReviewFindingModels [C:2] [TYPE Module] [SEMANTICS sqlalchemy, dataset, review, finding, validation]
# @BRIEF Validation finding model for tracking blocking, warning, and informational issues during review.
# @LAYER Domain
# @RELATION DEPENDS_ON -> [DatasetReviewEnums]
# @RELATION DEPENDS_ON -> [MappingModels]

from datetime import UTC, datetime
import uuid

from sqlalchemy import (
    Column,
    DateTime,
    Enum as SQLEnum,
    ForeignKey,
    String,
    Text,
)
from sqlalchemy.orm import relationship

from src.models.dataset_review_pkg._enums import (
    FindingArea,
    FindingSeverity,
    ResolutionState,
)
from src.models.mapping import Base


# #region ValidationFinding [C:2] [TYPE Class]
# @BRIEF Structured finding record for dataset review validation issues with resolution tracking.
# @RELATION DEPENDS_ON -> [DatasetReviewSession]
class ValidationFinding(Base):
    __tablename__ = "validation_findings"

    finding_id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
    session_id = Column(
        String, ForeignKey("dataset_review_sessions.session_id"), nullable=False
    )
    area = Column(SQLEnum(FindingArea), nullable=False)
    severity = Column(SQLEnum(FindingSeverity), nullable=False)
    code = Column(String, nullable=False)
    title = Column(String, nullable=False)
    message = Column(Text, nullable=False)
    resolution_state = Column(
        SQLEnum(ResolutionState), nullable=False, default=ResolutionState.OPEN
    )
    resolution_note = Column(Text, nullable=True)
    caused_by_ref = Column(String, nullable=True)
    created_at = Column(DateTime, default=lambda: datetime.now(UTC), nullable=False)
    resolved_at = Column(DateTime, nullable=True)

    session = relationship("DatasetReviewSession", back_populates="findings")


# #endregion ValidationFinding


# #endregion DatasetReviewFindingModels
