from datetime import datetime
from typing import TYPE_CHECKING, Optional
from models.base import BaseModel, BaseTableFields
from sqlmodel import Field, Relationship, Column, String

if TYPE_CHECKING:
    from models.user import User


class Session(BaseModel, BaseTableFields, table=True):
    __tablename__ = "sessions"

    access_token: str = Field(
        sa_column=Column(
            String,
            unique=True,
            nullable=False
        )
    )
    ip_address: Optional[str] = Field(
        sa_column=Column(
            String(100),
            nullable=True
        )
    )
    user_agent: Optional[str] = Field(
        sa_column=Column(
            String(100),
            nullable=True
        )
    )

    user_id: int = Field(foreign_key="users.id")
    user: "User" = 