from __future__ import annotations from datetime import datetime from sqlalchemy import Boolean, DateTime, JSON, SmallInteger, String, func from sqlalchemy.orm import Mapped, mapped_column from app.db.base import Base class PushPreference(Base): """ 用户推送偏好(以 client_user_id 为主键)。 """ __tablename__ = "push_preferences" client_user_id: Mapped[str] = mapped_column( String(length=64), primary_key=True, comment="客户端用户标识(UUID)", ) enabled: Mapped[bool] = mapped_column( Boolean, nullable=False, server_default="0", comment="是否开启每日提醒(enabled=false 或 times_per_day=0 均视为关闭)", ) times_per_day: Mapped[int] = mapped_column( SmallInteger, nullable=False, server_default="0", comment="每天推送次数(0~5)", ) timezone: Mapped[str | None] = mapped_column( String(length=64), nullable=True, comment="IANA 时区(例如 Asia/Shanghai),来自客户端上报", ) locale: Mapped[str | None] = mapped_column( String(length=32), nullable=True, comment="客户端语言(例如 zh-CN/en/zh-TW),用于文案语言选择", ) user_profile_json: Mapped[dict | None] = mapped_column( JSON, nullable=True, comment="用户画像(V1.2;可选)。用于 Push 场景推荐文案生成。", ) updated_at: Mapped[datetime] = mapped_column( DateTime, nullable=False, server_default=func.now(), server_onupdate=func.now(), comment="更新时间", )