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

class BlogPostBase(BaseModel):
    title: str = Field(..., min_length=1, max_length=500)
    slug: Optional[str] = None
    excerpt: Optional[str] = None
    content: str = Field(..., min_length=1)
    featured_image: Optional[str] = None
    tags: Optional[List[str]] = None
    meta_title: Optional[str] = Field(None, max_length=500)
    meta_description: Optional[str] = None
    meta_keywords: Optional[str] = Field(None, max_length=1000)
    is_published: bool = False
    published_at: Optional[datetime] = None
    sections: Optional[List[Dict[str, Any]]] = None  # Structured content sections

class BlogPostCreate(BlogPostBase):
    pass

class BlogPostUpdate(BaseModel):
    title: Optional[str] = Field(None, min_length=1, max_length=500)
    slug: Optional[str] = None
    excerpt: Optional[str] = None
    content: Optional[str] = Field(None, min_length=1)
    featured_image: Optional[str] = None
    tags: Optional[List[str]] = None
    meta_title: Optional[str] = Field(None, max_length=500)
    meta_description: Optional[str] = None
    meta_keywords: Optional[str] = Field(None, max_length=1000)
    is_published: Optional[bool] = None
    published_at: Optional[datetime] = None
    sections: Optional[List[Dict[str, Any]]] = None  # Structured content sections

class BlogPostResponse(BlogPostBase):
    id: int
    author_id: int
    author_name: Optional[str] = None
    views_count: int
    created_at: datetime
    updated_at: datetime
    
    class Config:
        from_attributes = True

class BlogPostListResponse(BaseModel):
    id: int
    title: str
    slug: str
    excerpt: Optional[str]
    featured_image: Optional[str]
    author_id: int
    author_name: Optional[str] = None
    published_at: Optional[datetime]
    views_count: int
    tags: Optional[List[str]] = None
    created_at: datetime
    
    class Config:
        from_attributes = True

