# #region DatasetReviewProfileModels [C:2] [TYPE Module] [SEMANTICS sqlalchemy, dataset, review, profile, summary]
# @BRIEF Dataset profile model capturing business summary, confidence, and completeness metadata.
# @LAYER Domain
# @RELATION DEPENDS_ON -> [DatasetReviewEnums]
# @RELATION DEPENDS_ON -> [MappingModels]

from datetime import UTC, datetime
import uuid

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

from src.models.dataset_review_pkg._enums import (
    BusinessSummarySource,
    ConfidenceState,
)
from src.models.mapping import Base


# #region DatasetProfile [C:2] [TYPE Class]
# @BRIEF One-to-one profile snapshot for a dataset review session, tracking business summary provenance and completeness.
# @RELATION DEPENDS_ON -> [DatasetReviewSession]
class DatasetProfile(Base):
    __tablename__ = "dataset_profiles"

    profile_id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
    session_id = Column(
        String,
        ForeignKey("dataset_review_sessions.session_id"),
        nullable=False,
        unique=True,
    )
    dataset_name = Column(String, nullable=False)
    schema_name = Column(String, nullable=True)
    database_name = Column(String, nullable=True)
    business_summary = Column(Text, nullable=False)
    business_summary_source = Column(SQLEnum(BusinessSummarySource), nullable=False)
    description = Column(Text, nullable=True)
    dataset_type = Column(String, nullable=True)
    is_sqllab_view = Column(Boolean, nullable=False, default=False)
    completeness_score = Column(Float, nullable=True)
    confidence_state = Column(SQLEnum(ConfidenceState), nullable=False)
    has_blocking_findings = Column(Boolean, nullable=False, default=False)
    has_warning_findings = Column(Boolean, nullable=False, default=False)
    manual_summary_locked = Column(Boolean, nullable=False, default=False)
    created_at = Column(DateTime, default=lambda: datetime.now(UTC), nullable=False)
    updated_at = Column(
        DateTime, default=lambda: datetime.now(UTC), onupdate=lambda: datetime.now(UTC), nullable=False
    )

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


# #endregion DatasetProfile


# #endregion DatasetReviewProfileModels
