from pydantic import BaseModel, Field
from typing import Optional, List
from datetime import datetime

class PostBase(BaseModel):
    content: str = Field(..., min_length=1, max_length=5000)

class PostCreate(PostBase):
    image_url: Optional[str] = None
    mentioned_user_ids: List[int] = []

class PostUpdate(BaseModel):
    content: Optional[str] = Field(None, min_length=1, max_length=5000)
    image_url: Optional[str] = None

class PostCommentCreate(BaseModel):
    content: str = Field(..., min_length=1, max_length=500)

class MentionedUser(BaseModel):
    id: int
    username: str
    full_name: str
    avatar_url: Optional[str]
    
    class Config:
        from_attributes = True

class PostCommentResponse(BaseModel):
    id: int
    content: str
    author_id: int
    author_name: str
    author_avatar: Optional[str]
    created_at: datetime
    
    class Config:
        from_attributes = True

class PostResponse(PostBase):
    id: int
    author_id: int
    author_name: str
    author_avatar: Optional[str]
    image_url: Optional[str]
    likes_count: int = 0
    comments_count: int = 0
    is_liked: Optional[bool] = None
    created_at: datetime
    updated_at: datetime
    mentioned_users: List[MentionedUser] = []
    comments: List[PostCommentResponse] = []
    
    class Config:
        from_attributes = True
