from __future__ import annotations

from datetime import datetime
from sqlalchemy import Integer, String, ForeignKey, DateTime, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column
from app.core.db.common import CommonBase

class InviteToken(CommonBase):
    __tablename__ = "invite_tokens"
    __table_args__ = (UniqueConstraint("token_hash", name="uq_invite_token_hash"),)

    id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
    user_id: Mapped[int] = mapped_column(ForeignKey("users.id", ondelete="CASCADE"), index=True)
    token_hash: Mapped[str] = mapped_column(String(64), index=True)
    created_at_utc: Mapped[datetime] = mapped_column(DateTime, nullable=False)
    expires_at_utc: Mapped[datetime] = mapped_column(DateTime, nullable=False)
    used_at_utc: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)

class PasswordResetToken(CommonBase):
    __tablename__ = "password_reset_tokens"
    __table_args__ = (UniqueConstraint("token_hash", name="uq_password_reset_token_hash"),)

    id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
    user_id: Mapped[int] = mapped_column(ForeignKey("users.id", ondelete="CASCADE"), index=True)
    token_hash: Mapped[str] = mapped_column(String(64), index=True)
    created_at_utc: Mapped[datetime] = mapped_column(DateTime, nullable=False)
    expires_at_utc: Mapped[datetime] = mapped_column(DateTime, nullable=False)
    used_at_utc: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
