from collections.abc import Hashable
from typing import Optional

from sqlalchemy import ColumnElement
from sqlalchemy.orm import Mapped

from advanced_alchemy.base import BigIntAuditBase
from advanced_alchemy.mixins import UniqueMixin


class Publisher(BigIntAuditBase, UniqueMixin):
    __tablename__ = "publishers"

    name: Mapped[str]
    description: Mapped[Optional[str]]

    @classmethod
    def unique_hash(cls, name: str) -> Hashable:
        """Generate a unique hash for deduplication."""
        return name

    @classmethod
    def unique_filter(cls, name: str) -> ColumnElement[bool]:
        """SQL filter for finding existing records."""
        return cls.name == name

    def __repr__(self) -> str:
        return f"Publisher({self.name!r})"
