import typing as t

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

from .discussions import DB_Discussion



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

    discussion_id: int = Field(foreign_key='discussions.id')
    discussion: t.Optional[DB_Discussion] = Relationship(back_populates='posts')
    """Discussion that this post belongs to."""

    number: int = Field(default=1)
    """The number/order of the post in the discussion."""
    created_at: datetime = Field(default=datetime.utcnow())
    """When was this post created. Default is now."""
    type: str = Field(max_length=100, default='comment')
    """The type of the post. Can be `'comment'` for standard post."""

    content: t.Text
    """The post's content, in HTML."""

    edited_at: t.Optional[datetime]
    """When was the post edited at?"""
    hidden_at: t.Optional[datetime]
    """When was the post hidden at?"""

    ip_address: t.Optional[str] = Field(max_length=45)
    """The IP address of the user that created the post."""

    is_private: bool = Field(default=False)
    """Whether or not the post is private."""
    is_approved: bool = Field(default=True)
    """Whether or not the post is approved."""

sqlmodel.Relationship sqlmodel.Field datetime.datetime.utcnow
[((235, 272), 'sqlmodel.Field', 'Field', ([], {'default': 'None', 'primary_key': '(True)'}), '(default=None, primary_key=True)\n', (240, 272), False, 'from sqlmodel import SQLModel, Field, Relationship\n'), ((362, 397), 'sqlmodel.Field', 'Field', ([], {'foreign_key': '"""discussions.id"""'}), "(foreign_key='discussions.id')\n", (367, 397), False, 'from sqlmodel import SQLModel, Field, Relationship\n'), ((442, 478), 'sqlmodel.Relationship', 'Relationship', ([], {'back_populates': '"""posts"""'}), "(back_populates='posts')\n", (454, 478), False, 'from sqlmodel import SQLModel, Field, Relationship\n'), ((546, 562), 'sqlmodel.Field', 'Field', ([], {'default': '(1)'}), '(default=1)\n', (551, 562), False, 'from sqlmodel import SQLModel, Field, Relationship\n'), ((751, 791), 'sqlmodel.Field', 'Field', ([], {'max_length': '(100)', 'default': '"""comment"""'}), "(max_length=100, default='comment')\n", (756, 791), False, 'from sqlmodel import SQLModel, Field, Relationship\n'), ((1108, 1128), 'sqlmodel.Field', 'Field', ([], {'max_length': '(45)'}), '(max_length=45)\n', (1113, 1128), False, 'from sqlmodel import SQLModel, Field, Relationship\n'), ((1213, 1233), 'sqlmodel.Field', 'Field', ([], {'default': '(False)'}), '(default=False)\n', (1218, 1233), False, 'from sqlmodel import SQLModel, Field, Relationship\n'), ((1304, 1323), 'sqlmodel.Field', 'Field', ([], {'default': '(True)'}), '(default=True)\n', (1309, 1323), False, 'from sqlmodel import SQLModel, Field, Relationship\n'), ((662, 679), 'datetime.datetime.utcnow', 'datetime.utcnow', ([], {}), '()\n', (677, 679), False, 'from datetime import datetime\n')]