"""Shared schemas used across multiple route modules."""

from datetime import datetime
from typing import Dict, Optional

from pydantic import BaseModel, Field


class ErrorResponse(BaseModel):
    """Error response."""

    error: str = Field(description="Error type")
    message: str = Field(description="Error message")
    detail: Optional[Dict] = Field(None, description="Additional error details")
    timestamp: datetime = Field(default_factory=datetime.utcnow, description="Error timestamp")


class CaptureImage(BaseModel):
    """Captured image with metadata."""

    image: str = Field(description="Base64-encoded thumbnail image data")
    full_image: Optional[str] = Field(None, description="Base64-encoded full-resolution image data")
    width: int = Field(description="Original image width in pixels")
    height: int = Field(description="Original image height in pixels")
    thumbnail_width: Optional[int] = Field(None, description="Thumbnail width (if resized)")
    thumbnail_height: Optional[int] = Field(None, description="Thumbnail height (if resized)")


class BorderExtraction(BaseModel):
    """Extracted border images."""

    top: str = Field(description="Base64-encoded top border image")
    right: str = Field(description="Base64-encoded right border image")
    bottom: str = Field(description="Base64-encoded bottom border image")
    left: str = Field(description="Base64-encoded left border image")


class PerformanceMetrics(BaseModel):
    """Performance metrics for template test."""

    capture_duration_s: float = Field(description="Total capture duration in seconds")
    frame_count: int = Field(description="Number of frames captured")
    actual_fps: float = Field(description="Actual FPS (frame_count / duration)")
    avg_capture_time_ms: float = Field(description="Average time per frame capture in milliseconds")


class TemplateTestResponse(BaseModel):
    """Response from template test."""

    full_capture: CaptureImage = Field(description="Full screen capture with thumbnail")
    border_extraction: Optional[BorderExtraction] = Field(None, description="Extracted border images (deprecated)")
    performance: PerformanceMetrics = Field(description="Performance metrics")
