"""Sync clock schemas (CRUD + control)."""

from datetime import datetime
from typing import List, Optional

from pydantic import BaseModel, Field


class SyncClockCreate(BaseModel):
    """Request to create a synchronization clock."""

    name: str = Field(description="Clock name", min_length=1, max_length=100)
    speed: float = Field(default=1.0, description="Speed multiplier (0.1–10.0)", ge=0.1, le=10.0)
    description: Optional[str] = Field(None, description="Optional description", max_length=500)
    tags: List[str] = Field(default_factory=list, description="User-defined tags")


class SyncClockUpdate(BaseModel):
    """Request to update a synchronization clock."""

    name: Optional[str] = Field(None, description="Clock name", min_length=1, max_length=100)
    speed: Optional[float] = Field(None, description="Speed multiplier (0.1–10.0)", ge=0.1, le=10.0)
    description: Optional[str] = Field(None, description="Optional description", max_length=500)
    tags: Optional[List[str]] = None


class SyncClockResponse(BaseModel):
    """Synchronization clock response."""

    id: str = Field(description="Clock ID")
    name: str = Field(description="Clock name")
    speed: float = Field(description="Speed multiplier")
    description: Optional[str] = Field(None, description="Description")
    tags: List[str] = Field(default_factory=list, description="User-defined tags")
    is_running: bool = Field(True, description="Whether clock is currently running")
    elapsed_time: float = Field(0.0, description="Current elapsed time in seconds")
    created_at: datetime = Field(description="Creation timestamp")
    updated_at: datetime = Field(description="Last update timestamp")


class SyncClockListResponse(BaseModel):
    """List of synchronization clocks."""

    clocks: List[SyncClockResponse] = Field(description="List of sync clocks")
    count: int = Field(description="Number of clocks")
