"""MAX identifiers and delivery metadata live only in the identity DB; no medical message bodies.""" from datetime import datetime from sqlalchemy import BigInteger, Boolean, Integer, String from sqlalchemy.orm import Mapped, mapped_column from app.db.identity import IdentityBase from app.db.types import TZDateTime class MaxBinding(IdentityBase): __tablename__ = "max_bindings" # No FK: anonymous web profiles intentionally have no patients row in identity. token: Mapped[str] = mapped_column(String(64), primary_key=True) user_id: Mapped[int] = mapped_column(BigInteger, unique=True) enabled: Mapped[bool] = mapped_column(Boolean, default=True) connected_at: Mapped[datetime] = mapped_column(TZDateTime) class MaxLinkCode(IdentityBase): __tablename__ = "max_link_codes" digest: Mapped[str] = mapped_column(String(64), primary_key=True) token: Mapped[str] = mapped_column(String(64), unique=True) expires_at: Mapped[datetime] = mapped_column(TZDateTime, index=True) used_at: Mapped[datetime | None] = mapped_column(TZDateTime) class MaxReceipt(IdentityBase): __tablename__ = "max_webhook_receipts" digest: Mapped[str] = mapped_column(String(64), primary_key=True) received_at: Mapped[datetime] = mapped_column(TZDateTime, index=True) class MaxDelivery(IdentityBase): __tablename__ = "max_deliveries" id: Mapped[str] = mapped_column(String(64), primary_key=True) token: Mapped[str | None] = mapped_column(String(64), index=True) user_id: Mapped[int] = mapped_column(BigInteger) kind: Mapped[str] = mapped_column(String(24)) state: Mapped[str] = mapped_column(String(16), default="queued", index=True) attempts: Mapped[int] = mapped_column(Integer, default=0) created_at: Mapped[datetime] = mapped_column(TZDateTime) next_attempt_at: Mapped[datetime] = mapped_column(TZDateTime, index=True) lease: Mapped[str | None] = mapped_column(String(32)) error_code: Mapped[str | None] = mapped_column(String(32))