"""SQLAlchemy model for one-time password setup/reset tokens. Issued when an admin sends a "set your password" email — a passwordless user (freshly created, or one whose password an admin wants to reset) uses the token to pick their own password without ever having a temporary one shared with them. """ import uuid from sqlalchemy import Column, DateTime, ForeignKey, String, func from sqlalchemy.dialects.postgresql import UUID from sqlalchemy.orm import relationship from app.database import Base class PasswordSetupToken(Base): """A one-time token letting its owning user set their own password.""" __tablename__ = "password_setup_tokens" id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) user_id = Column(UUID(as_uuid=True), ForeignKey("users.id"), nullable=False) token = Column(String(128), unique=True, nullable=False, index=True) expires_at = Column(DateTime, nullable=False) used_at = Column(DateTime, nullable=True) created_at = Column(DateTime(timezone=True), server_default=func.now()) user = relationship("User", foreign_keys=[user_id])