"""引导视频待播放计划、起播快照与逐圈结算状态。""" from __future__ import annotations from datetime import datetime from sqlalchemy import DateTime, ForeignKey, Index, Integer, String, UniqueConstraint, func from sqlalchemy.orm import Mapped, mapped_column from app.db.base import Base class GuideVideoPlay(Base): __tablename__ = "guide_video_play" __table_args__ = ( UniqueConstraint("play_token", name="uq_guide_video_play_token"), Index( "uq_guide_video_play_user_scene_seq", "user_id", "scene", "seq", unique=True, ), ) id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) user_id: Mapped[int] = mapped_column( Integer, ForeignKey("user.id"), index=True, nullable=False ) play_token: Mapped[str] = mapped_column(String(64), nullable=False) scene: Mapped[str] = mapped_column(String(16), nullable=False, default="coupon") # prepare 不占次数,seq=NULL;start 成功才写入 1-based seq。 seq: Mapped[int | None] = mapped_column(Integer, nullable=True) video_url: Mapped[str | None] = mapped_column(String(512), nullable=True) coin: Mapped[int] = mapped_column(Integer, nullable=False, default=0) duration_ms: Mapped[int] = mapped_column(Integer, nullable=False, default=0) config_version: Mapped[int] = mapped_column(Integer, nullable=False, default=0) settled_circles: Mapped[int] = mapped_column(Integer, nullable=False, default=0) # prepared / started / completed / legacy_completed / legacy_closed status: Mapped[str] = mapped_column(String(24), nullable=False, default="prepared") completed: Mapped[int] = mapped_column(Integer, nullable=False, default=0) prepared_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), server_default=func.now(), nullable=False ) expires_at: Mapped[datetime | None] = mapped_column( DateTime(timezone=True), index=True, nullable=True ) started_at: Mapped[datetime | None] = mapped_column( DateTime(timezone=True), index=True, nullable=True ) granted_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True) def __repr__(self) -> str: # pragma: no cover return ( f"" )