from __future__ import annotations

from typing import Optional

from sqlalchemy import ForeignKey
from sqlalchemy.orm import Mapped, mapped_column

from advanced_alchemy.base import BigIntAuditBase


class KosyncProgress(BigIntAuditBase):
    """Progress tracking for KOReader devices, keyed by document hash."""

    __tablename__ = "kosync_progress"

    user_id: Mapped[int] = mapped_column(
        ForeignKey("users.id", ondelete="cascade"), nullable=False
    )
    book_id: Mapped[int] = mapped_column(
        ForeignKey("books.id", ondelete="cascade"), nullable=False
    )
    document: Mapped[str] = mapped_column(nullable=False)
    progress: Mapped[Optional[str]]
    percentage: Mapped[Optional[float]]
    device: Mapped[Optional[str]]
    device_id: Mapped[Optional[str]]
