import uuid

from sqlalchemy import String, Text
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import Mapped, mapped_column, relationship

from api.models.base import Base, TimestampMixin, new_uuid


class Domain(Base, TimestampMixin):
    __tablename__ = "domains"

    id: Mapped[uuid.UUID] = mapped_column(
        UUID(as_uuid=True), primary_key=True, default=new_uuid
    )
    slug: Mapped[str] = mapped_column(String(50), unique=True, nullable=False, index=True)
    name: Mapped[str] = mapped_column(String(200), nullable=False)
    description: Mapped[str | None] = mapped_column(Text, nullable=True)
    status: Mapped[str] = mapped_column(String(20), nullable=False, default="active")

    topics: Mapped[list["Topic"]] = relationship(  # noqa: F821
        "Topic", back_populates="domain", lazy="selectin"
    )
    repos: Mapped[list["ManagedRepo"]] = relationship(  # noqa: F821
        "ManagedRepo", back_populates="domain", lazy="selectin"
    )
    goals: Mapped[list["DomainGoal"]] = relationship(  # noqa: F821
        "DomainGoal", back_populates="domain", lazy="selectin"
    )
