"""Postprocessing template schemas."""

from datetime import datetime
from typing import List, Optional

from pydantic import BaseModel, Field

from .filters import FilterInstanceSchema


class PostprocessingTemplateCreate(BaseModel):
    """Request to create a postprocessing template."""

    name: str = Field(description="Template name", min_length=1, max_length=100)
    filters: List[FilterInstanceSchema] = Field(default_factory=list, description="Ordered list of filter instances")
    description: Optional[str] = Field(None, description="Template description", max_length=500)
    tags: List[str] = Field(default_factory=list, description="User-defined tags")


class PostprocessingTemplateUpdate(BaseModel):
    """Request to update a postprocessing template."""

    name: Optional[str] = Field(None, description="Template name", min_length=1, max_length=100)
    filters: Optional[List[FilterInstanceSchema]] = Field(None, description="Ordered list of filter instances")
    description: Optional[str] = Field(None, description="Template description", max_length=500)
    tags: Optional[List[str]] = None


class PostprocessingTemplateResponse(BaseModel):
    """Postprocessing template information response."""

    id: str = Field(description="Template ID")
    name: str = Field(description="Template name")
    filters: List[FilterInstanceSchema] = Field(description="Ordered list of filter instances")
    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 PostprocessingTemplateListResponse(BaseModel):
    """List of postprocessing templates response."""

    templates: List[PostprocessingTemplateResponse] = Field(description="List of postprocessing templates")
    count: int = Field(description="Number of templates")


class PPTemplateTestRequest(BaseModel):
    """Request to test a postprocessing template against a source stream."""

    source_stream_id: str = Field(description="ID of the source picture source to capture from")
    capture_duration: float = Field(default=5.0, ge=1.0, le=30.0, description="Duration to capture in seconds")
