from pydantic import BaseModel, Field
from typing import Optional, List
from datetime import datetime
from models.album import MediaType

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

class AlbumCreate(AlbumBase):
    cover_image: Optional[str] = None

class AlbumUpdate(BaseModel):
    title: Optional[str] = Field(None, min_length=1, max_length=200)
    description: Optional[str] = None
    event_id: Optional[int] = None
    cover_image: Optional[str] = None

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

class MediaResponse(BaseModel):
    id: int
    file_path: str
    thumbnail_path: Optional[str]
    media_type: MediaType
    caption: Optional[str]
    file_size: int
    width: Optional[int]
    height: Optional[int]
    duration: Optional[int]
    likes_count: int
    is_liked: Optional[bool] = None
    likes: List[MediaLikeResponse] = []
    created_at: datetime
    
    class Config:
        from_attributes = True

class AlbumResponse(AlbumBase):
    id: int
    creator_id: int
    creator_name: str
    cover_image: Optional[str]
    created_at: datetime
    media_count: int = 0
    media: List[MediaResponse] = []
    event_title: Optional[str] = None
    top_media: List[MediaResponse] = []
    
    class Config:
        from_attributes = True
