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

class VlogBase(BaseModel):
    title: str = Field(..., min_length=1, max_length=200)
    description: Optional[str] = None

class VlogCreate(VlogBase):
    video_url: str
    thumbnail_url: Optional[str] = None
    duration: Optional[int] = None

class VlogUpdate(BaseModel):
    title: Optional[str] = Field(None, min_length=1, max_length=200)
    description: Optional[str] = None
    thumbnail_url: Optional[str] = None

class VlogLikeResponse(BaseModel):
    id: int
    user_id: int
    username: str
    full_name: str
    avatar_url: Optional[str]
    created_at: datetime
    
    class Config:
        from_attributes = True

class VlogCommentResponse(BaseModel):
    id: int
    user_id: int
    username: str
    full_name: str
    avatar_url: Optional[str]
    content: str
    created_at: datetime
    updated_at: datetime
    
    class Config:
        from_attributes = True

class VlogResponse(VlogBase):
    id: int
    author_id: int
    author_name: str
    author_avatar: Optional[str]
    video_url: str
    thumbnail_url: Optional[str]
    duration: Optional[int]
    views_count: int
    replays_count: int = 0
    likes_count: int
    created_at: datetime
    updated_at: datetime
    is_liked: Optional[bool] = None
    likes: List[VlogLikeResponse] = []
    comments: List[VlogCommentResponse] = []
    
    class Config:
        from_attributes = True

class VlogCommentCreate(BaseModel):
    content: str = Field(..., min_length=1, max_length=1000)
