from typing import Optional
from sqlalchemy import ForeignKey
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy.orm import relationship
from advanced_alchemy.base import BigIntAuditBase


class BookProgress(BigIntAuditBase):
    __tablename__ = "book_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
    )

    epub_cfi: Mapped[Optional[str]]
    epub_xpointer: Mapped[Optional[str]]
    pdf_page: Mapped[Optional[int]]
    percentage: Mapped[float]
    completed: Mapped[Optional[bool]]
    device: Mapped[Optional[str]] # Device that updated the progress
    device_id: Mapped[Optional[str]]
