"""Scene preset API schemas."""

from datetime import datetime
from typing import List, Optional

from pydantic import BaseModel, Field


class TargetSnapshotSchema(BaseModel):
    target_id: str
    running: bool = False
    color_strip_source_id: str = ""
    brightness_value_source_id: str = ""
    fps: int = 30


class ScenePresetCreate(BaseModel):
    """Create a scene preset by capturing current state."""

    name: str = Field(description="Preset name", min_length=1, max_length=100)
    description: str = Field(default="", max_length=500)
    target_ids: Optional[List[str]] = Field(None, description="Target IDs to capture (all if omitted)")
    tags: List[str] = Field(default_factory=list, description="User-defined tags")


class ScenePresetUpdate(BaseModel):
    """Update scene preset metadata and optionally change which targets are included."""

    name: Optional[str] = Field(None, min_length=1, max_length=100)
    description: Optional[str] = Field(None, max_length=500)
    order: Optional[int] = None
    target_ids: Optional[List[str]] = Field(None, description="Update target list: keep state for existing, capture fresh for new, drop removed")
    tags: Optional[List[str]] = None


class ScenePresetResponse(BaseModel):
    """Scene preset with full snapshot data."""

    id: str
    name: str
    description: str
    targets: List[TargetSnapshotSchema]
    order: int
    tags: List[str] = Field(default_factory=list, description="User-defined tags")
    created_at: datetime
    updated_at: datetime


class ScenePresetListResponse(BaseModel):
    presets: List[ScenePresetResponse]
    count: int


class ActivateResponse(BaseModel):
    status: str = Field(description="'activated' or 'partial'")
    errors: List[str] = Field(default_factory=list)
