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

from datetime import datetime
from typing import List

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: str | None = Field(None, description="Optional description", max_length=500)
    tags: List[str] = Field(default_factory=list, description="User-defined tags")
    icon: str | None = Field(
        None,
        max_length=64,
        description="Icon id from the curated icon library. Pass empty string to clear.",
    )
    icon_color: str | None = Field(
        None,
        max_length=32,
        description="Optional CSS color override for the icon (e.g. '#4CAF50'). Empty/null inherits the channel accent.",
    )


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

    name: str | None = Field(None, description="Clock name", min_length=1, max_length=100)
    speed: float | None = Field(None, description="Speed multiplier (0.1–10.0)", ge=0.1, le=10.0)
    description: str | None = Field(None, description="Optional description", max_length=500)
    tags: List[str] | None = None
    icon: str | None = Field(
        None,
        max_length=64,
        description="Icon id from the curated icon library. Pass empty string to clear.",
    )
    icon_color: str | None = Field(
        None,
        max_length=32,
        description="Optional CSS color override for the icon. Pass empty string to inherit the channel accent.",
    )


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: str | None = Field(None, description="Description")
    tags: List[str] = Field(default_factory=list, description="User-defined tags")
    icon: str | None = Field(
        None,
        max_length=64,
        description="Icon id from the curated icon library.",
    )
    icon_color: str | None = Field(
        None,
        max_length=32,
        description="Optional CSS color override for the icon.",
    )
    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")
