# app/schemas/list.py
from pydantic import BaseModel, ConfigDict
from datetime import datetime
from typing import Optional, List

from .item import ItemPublic # Import item schema for nesting

# Properties to receive via API on creation
class ListCreate(BaseModel):
    name: str
    description: Optional[str] = None
    group_id: Optional[int] = None # Optional for sharing

# Properties to receive via API on update
class ListUpdate(BaseModel):
    name: Optional[str] = None
    description: Optional[str] = None
    is_complete: Optional[bool] = None
    version: int # Client must provide the version for updates
    # Potentially add group_id update later if needed

# Base properties returned by API (common fields)
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 # Include version in responses

    model_config = ConfigDict(from_attributes=True)

# Properties returned when listing lists (no items)
class ListPublic(ListBase):
    pass # Inherits all from ListBase

# Properties returned for a single list detail (includes items)
class ListDetail(ListBase):
    items: List[ItemPublic] = [] # Include list of items

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

class ListStatusWithId(ListStatus):
    id: int