"""Pydantic schemas for pattern template API."""

from datetime import datetime
from typing import List, Optional

from pydantic import BaseModel, Field

from .output_targets import KeyColorRectangleSchema


class PatternTemplateCreate(BaseModel):
    """Request to create a pattern template."""

    name: str = Field(description="Template name", min_length=1, max_length=100)
    rectangles: List[KeyColorRectangleSchema] = Field(default_factory=list, description="List of named rectangles")
    description: Optional[str] = Field(None, description="Template description", max_length=500)
    tags: List[str] = Field(default_factory=list, description="User-defined tags")


class PatternTemplateUpdate(BaseModel):
    """Request to update a pattern template."""

    name: Optional[str] = Field(None, description="Template name", min_length=1, max_length=100)
    rectangles: Optional[List[KeyColorRectangleSchema]] = Field(None, description="List of named rectangles")
    description: Optional[str] = Field(None, description="Template description", max_length=500)
    tags: Optional[List[str]] = None


class PatternTemplateResponse(BaseModel):
    """Pattern template response."""

    id: str = Field(description="Template ID")
    name: str = Field(description="Template name")
    rectangles: List[KeyColorRectangleSchema] = Field(description="List of named rectangles")
    tags: List[str] = Field(default_factory=list, description="User-defined tags")
    created_at: datetime = Field(description="Creation timestamp")
    updated_at: datetime = Field(description="Last update timestamp")
    description: Optional[str] = Field(None, description="Template description")


class PatternTemplateListResponse(BaseModel):
    """List of pattern templates."""

    templates: List[PatternTemplateResponse] = Field(description="List of pattern templates")
    count: int = Field(description="Number of templates")
