import typing as t

if t.TYPE_CHECKING:
    from .other import DB_AccessToken, DB_APIKey
    from .discussions import DB_Discussion

from datetime import datetime

from sqlmodel import SQLModel, Field, Relationship, Column, JSON
from ..extensions.tags import DB_Tag, DB_TagUser



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

    username: str = Field(max_length=100, sa_column_kwargs={"unique": True})
    """The user's username."""

    email: str = Field(max_length=150, sa_column_kwargs={"unique": True})
    """The user's E-mail address."""
    is_email_confirmed: bool = Field(default=False)
    """Whether or not the user confirmed their E-mail address."""
    password: str = Field(max_length=100)
    """The user's password (<PASSWORD>)."""

    avatar_url: t.Optional[str] = Field(max_length=100)
    """The file name of user's avatar. Avatars are located in the `public/assets/avatars` directory of your forum root."""
    preferences: t.Dict[str, bool] = Field(sa_column=Column(JSON), default={"notify_discussionRenamed_alert": True,"notify_postLiked_alert": True,"notify_discussionLocked_alert": True,"notify_postMentioned_alert": True,"notify_postMentioned_email": False,"notify_userMentioned_alert": True,"notify_userMentioned_email": False,"notify_newPost_alert": True, "notify_newPost_email": True, "notify_userSuspended_alert": True, "notify_userUnsuspended_alert": True, "followAfterReply": True, "discloseOnline": True, "indexProfile": True, "locale": None })
    """The user's preferences (e. g.: for notifications)."""

    joined_at: t.Optional[datetime] = Field(default=None)
    """When did the user join the forum."""
    last_seen_at: t.Optional[datetime] = Field(default=None)
    """When was the user last seen at."""
    marked_all_as_read_at: t.Optional[datetime] = Field(default=None)
    """When did the user mark all discussions as read."""
    read_notifications_at: t.Optional[datetime] = Field(default=None)
    """When did the user read their notifications."""

    discussion_count: int = Field(default=0)
    """The user's discussion count."""
    comment_count: int = Field(default=0)
    """The user's comment (post) count."""

    access_tokens: t.List['DB_AccessToken'] = Relationship(back_populates='user')
    """List of access tokens belonging to this user."""
    api_keys: t.List['DB_APIKey'] = Relationship(back_populates='user')
    """List of API keys that perform actions on behalf of this user."""
    discussions: t.List['DB_Discussion'] = Relationship(back_populates='author')
    """List of discussions that this user made."""

    tags: t.List['DB_Tag'] = Relationship(back_populates='users', link_model=DB_TagUser)
    """Tags that have relationship with this user."""

sqlmodel.Relationship sqlmodel.Field sqlmodel.Column
[((372, 409), 'sqlmodel.Field', 'Field', ([], {'default': 'None', 'primary_key': '(True)'}), '(default=None, primary_key=True)\n', (377, 409), False, 'from sqlmodel import SQLModel, Field, Relationship, Column, JSON\n'), ((494, 550), 'sqlmodel.Field', 'Field', ([], {'max_length': '(100)', 'sa_column_kwargs': "{'unique': True}"}), "(max_length=100, sa_column_kwargs={'unique': True})\n", (499, 550), False, 'from sqlmodel import SQLModel, Field, Relationship, Column, JSON\n'), ((600, 656), 'sqlmodel.Field', 'Field', ([], {'max_length': '(150)', 'sa_column_kwargs': "{'unique': True}"}), "(max_length=150, sa_column_kwargs={'unique': True})\n", (605, 656), False, 'from sqlmodel import SQLModel, Field, Relationship, Column, JSON\n'), ((725, 745), 'sqlmodel.Field', 'Field', ([], {'default': '(False)'}), '(default=False)\n', (730, 745), False, 'from sqlmodel import SQLModel, Field, Relationship, Column, JSON\n'), ((832, 853), 'sqlmodel.Field', 'Field', ([], {'max_length': '(100)'}), '(max_length=100)\n', (837, 853), False, 'from sqlmodel import SQLModel, Field, Relationship, Column, JSON\n'), ((933, 954), 'sqlmodel.Field', 'Field', ([], {'max_length': '(100)'}), '(max_length=100)\n', (938, 954), False, 'from sqlmodel import SQLModel, Field, Relationship, Column, JSON\n'), ((1728, 1747), 'sqlmodel.Field', 'Field', ([], {'default': 'None'}), '(default=None)\n', (1733, 1747), False, 'from sqlmodel import SQLModel, Field, Relationship, Column, JSON\n'), ((1833, 1852), 'sqlmodel.Field', 'Field', ([], {'default': 'None'}), '(default=None)\n', (1838, 1852), False, 'from sqlmodel import SQLModel, Field, Relationship, Column, JSON\n'), ((1945, 1964), 'sqlmodel.Field', 'Field', ([], {'default': 'None'}), '(default=None)\n', (1950, 1964), False, 'from sqlmodel import SQLModel, Field, Relationship, Column, JSON\n'), ((2073, 2092), 'sqlmodel.Field', 'Field', ([], {'default': 'None'}), '(default=None)\n', (2078, 2092), False, 'from sqlmodel import SQLModel, Field, Relationship, Column, JSON\n'), ((2176, 2192), 'sqlmodel.Field', 'Field', ([], {'default': '(0)'}), '(default=0)\n', (2181, 2192), False, 'from sqlmodel import SQLModel, Field, Relationship, Column, JSON\n'), ((2257, 2273), 'sqlmodel.Field', 'Field', ([], {'default': '(0)'}), '(default=0)\n', (2262, 2273), False, 'from sqlmodel import SQLModel, Field, Relationship, Column, JSON\n'), ((2364, 2399), 'sqlmodel.Relationship', 'Relationship', ([], {'back_populates': '"""user"""'}), "(back_populates='user')\n", (2376, 2399), False, 'from sqlmodel import SQLModel, Field, Relationship, Column, JSON\n'), ((2492, 2527), 'sqlmodel.Relationship', 'Relationship', ([], {'back_populates': '"""user"""'}), "(back_populates='user')\n", (2504, 2527), False, 'from sqlmodel import SQLModel, Field, Relationship, Column, JSON\n'), ((2643, 2680), 'sqlmodel.Relationship', 'Relationship', ([], {'back_populates': '"""author"""'}), "(back_populates='author')\n", (2655, 2680), False, 'from sqlmodel import SQLModel, Field, Relationship, Column, JSON\n'), ((2762, 2821), 'sqlmodel.Relationship', 'Relationship', ([], {'back_populates': '"""users"""', 'link_model': 'DB_TagUser'}), "(back_populates='users', link_model=DB_TagUser)\n", (2774, 2821), False, 'from sqlmodel import SQLModel, Field, Relationship, Column, JSON\n'), ((1131, 1143), 'sqlmodel.Column', 'Column', (['JSON'], {}), '(JSON)\n', (1137, 1143), False, 'from sqlmodel import SQLModel, Field, Relationship, Column, JSON\n')]