"""Group database model.""" from datetime import datetime, timezone from typing import TYPE_CHECKING from uuid import UUID, uuid4 from sqlalchemy import DateTime, ForeignKey, String, Text from sqlalchemy.dialects.postgresql import UUID as PGUUID from sqlalchemy.orm import Mapped, mapped_column, relationship from app.database.base import Base if TYPE_CHECKING: from app.database.models.board import Board from app.database.models.board_image import BoardImage class Group(Base): """ Group model for organizing images with labels and annotations. Groups contain multiple images that can be moved together and have shared visual indicators (color, annotation text). """ __tablename__ = "groups" id: Mapped[UUID] = mapped_column(PGUUID(as_uuid=True), primary_key=True, default=uuid4) board_id: Mapped[UUID] = mapped_column( PGUUID(as_uuid=True), ForeignKey("boards.id", ondelete="CASCADE"), nullable=False ) name: Mapped[str] = mapped_column(String(255), nullable=False) color: Mapped[str] = mapped_column(String(7), nullable=False) # Hex color #RRGGBB annotation: Mapped[str | None] = mapped_column(Text, nullable=True) created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False, default=lambda: datetime.now(timezone.utc)) updated_at: Mapped[datetime] = mapped_column( DateTime, nullable=False, default=lambda: datetime.now(timezone.utc), onupdate=lambda: datetime.now(timezone.utc) ) # Relationships board: Mapped["Board"] = relationship("Board", back_populates="groups") board_images: Mapped[list["BoardImage"]] = relationship("BoardImage", back_populates="group") def __repr__(self) -> str: """String representation of Group.""" return f""