"""WebSocket device provider — factory, validation, health checks."""

from datetime import datetime, timezone
from typing import List

from wled_controller.core.devices.led_client import (
    DeviceHealth,
    DiscoveredDevice,
    LEDClient,
    LEDDeviceProvider,
)
from wled_controller.core.devices.ws_client import WSLEDClient
from wled_controller.utils import get_logger

logger = get_logger(__name__)


class WSDeviceProvider(LEDDeviceProvider):
    """Provider for WebSocket-based virtual LED devices."""

    @property
    def device_type(self) -> str:
        return "ws"

    @property
    def capabilities(self) -> set:
        return {"manual_led_count"}

    def create_client(self, url: str, **kwargs) -> LEDClient:
        return WSLEDClient(
            url,
            led_count=kwargs.get("led_count", 0),
        )

    async def check_health(
        self, url: str, http_client, prev_health=None,
    ) -> DeviceHealth:
        return DeviceHealth(
            online=True, latency_ms=0.0, last_checked=datetime.now(timezone.utc),
        )

    async def validate_device(self, url: str) -> dict:
        """Validate WS device URL — accepts any URL since it will be auto-set."""
        return {}

    async def discover(self, timeout: float = 3.0) -> List[DiscoveredDevice]:
        return []
