"""User-preference schemas (notifications, future per-user settings)."""

from typing import Literal

from pydantic import BaseModel, Field

NotificationChannel = Literal["none", "snack", "os", "both"]


class NotificationChannelMatrix(BaseModel):
    """Channel selection per device-event type."""

    device_online: NotificationChannel = Field(
        default="snack",
        description="Configured device transitioned from offline to online",
    )
    device_offline: NotificationChannel = Field(
        default="both",
        description="Configured device went offline (urgent — likely user wants OS toast)",
    )
    device_discovered: NotificationChannel = Field(
        default="snack",
        description="A new WLED/serial device appeared on the LAN/USB",
    )
    device_lost: NotificationChannel = Field(
        default="none",
        description=(
            "Previously discovered (but never configured) device disappeared. "
            "Default off — usually noise unless the user is actively pairing."
        ),
    )


class NotificationPreferences(BaseModel):
    """User-level notification preferences."""

    channels: NotificationChannelMatrix = Field(
        default_factory=NotificationChannelMatrix,
        description="Per-event-type channel selection",
    )
    background_discovery_enabled: bool = Field(
        default=True,
        description=(
            "Run the continuous mDNS browser + serial-port poller while the server "
            "is up. Required for device_discovered/device_lost notifications. "
            "Disable to silence all discovery-driven events at the source."
        ),
    )
    startup_grace_sec: int = Field(
        default=10,
        ge=0,
        le=300,
        description=(
            "Seconds after each event-WS connect during which device_offline "
            "notifications are suppressed (devices boot at different speeds)."
        ),
    )
    flap_debounce_sec: int = Field(
        default=5,
        ge=0,
        le=60,
        description=(
            "A device must hold a new state for at least this many seconds before "
            "the corresponding notification is fired. Filters out single-packet drops."
        ),
    )
