"""TagAlias — maps a model's (name, category) prediction to the operator's
canonical tag. Resolved at suggestion-read time so the raw predictions stored
in image_prediction stay unmolested.
"""

from datetime import datetime

from sqlalchemy import DateTime, ForeignKey, String, func
from sqlalchemy.orm import Mapped, mapped_column

from .base import Base


class TagAlias(Base):
    __tablename__ = "tag_alias"

    alias_string: Mapped[str] = mapped_column(String(255), primary_key=True)
    alias_category: Mapped[str] = mapped_column(String(32), primary_key=True)
    canonical_tag_id: Mapped[int] = mapped_column(
        ForeignKey("tag.id", ondelete="CASCADE"), nullable=False, index=True
    )
    created_at: Mapped[datetime] = mapped_column(
        DateTime(timezone=True), nullable=False, server_default=func.now()
    )
