import typing as t

from sqlmodel import SQLModel, Field, Relationship
from datetime import datetime

from .users import DB_User



class DB_AccessToken(SQLModel, table=True):
    __tablename__ = 'access_tokens'
    id: t.Optional[int] = Field(default=None, primary_key=True)
    """The ID of the access token. This is handled by the database."""

    token: str = Field(max_length=40, sa_column_kwargs={'unique': True})
    """The unique access token."""
    user_id: t.Optional[int] = Field(default=None, foreign_key="users.id")
    user: DB_User = Relationship(back_populates="access_tokens")
    """To what user does this token belong to."""

    last_activity_at: datetime
    """When was the access token last active."""
    created_at: datetime
    """When was this token created at?"""

    type: str = 