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

from .item import ItemPublic

class ListCreate(BaseModel):
    name: str
    description: Optional[str] = None
    group_id: Optional[int] = None

class ListUpdate(BaseModel):
    name: Optional[str] = None
    description: Optional[str] = None
    is_complete: Optional[bool] = None
    version: int

class ListBase(BaseModel):
    id: int
    name: str
    description: Optional[str] = None
    created_by_id: int
    group_id: Optional[int] = None
    is_complete: bool
    created_at: datetime
    updated_at: datetime
    version: int

    model_config = ConfigDict(from_attributes=True)

class ListPublic(ListBase):
    pass

class ListDetail(ListBase):
    items: List[ItemPublic] = []

class ListStatus(BaseModel):
    updated_at: datetime
    item_count: int
    latest_item_updated_at: Optional[datetime] = None

class ListStatusWithId(ListStatus):
    id: int