import enum
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, Enum
from sqlalchemy.sql import func
from app.db.base import Base

class TokenType(str, enum.Enum):
    email_verify = "email_verify"
    password_reset = "password_reset"

class VerificationToken(Base):
    __tablename__ = "verification_tokens"
    __table_args__ = {"schema": "data"}

    id = Column(Integer, primary_key=True, index=True)
    user_id = Column(Integer, ForeignKey("data.users.id", ondelete="CASCADE"), nullable=False)

    token_hash = Column(String(64), unique=True, index=True, nullable=False)
    token_type = Column(Enum(TokenType, name="tokentype", schema="data"), nullable=False)

    expires_at = Column(DateTime(timezone=True), nullable=True)
    created_at = Column(DateTime(timezone=True), server_default=func.now(), nullable=False)
