from collections.abc import Hashable
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy import ColumnElement, ForeignKey

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

from .book import Book


class BookSeries(BigIntAuditBase, UniqueMixin):
    __tablename__ = "book_series"

    title: Mapped[str] = mapped_column(unique=True, index=True)

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

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