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] = 