"""Group device provider — virtual device that aggregates multiple child devices."""

from __future__ import annotations

from datetime import datetime, timezone
from typing import TYPE_CHECKING, List

from ledgrab.core.devices.led_client import (
    DeviceHealth,
    DiscoveredDevice,
    LEDClient,
    LEDDeviceProvider,
    ProviderDeps,
)
from ledgrab.core.devices.group_client import GroupLEDClient

if TYPE_CHECKING:
    from ledgrab.core.devices.device_config import GroupConfig


class GroupDeviceProvider(LEDDeviceProvider):
    """Provider for group devices that aggregate multiple child devices."""

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

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

    def create_client(self, config: "GroupConfig", *, deps: ProviderDeps) -> LEDClient:
        return GroupLEDClient(config=config, deps=deps)

    async def check_health(self, url: str, http_client, prev_health=None) -> DeviceHealth:
        # Group health is aggregated by the processor manager from children's health.
        # This fallback marks the group as online since it's a virtual device.
        return DeviceHealth(online=True, latency_ms=0.0, last_checked=datetime.now(timezone.utc))

    async def validate_device(self, url: str) -> dict:
        # Group devices are virtual — no URL validation needed.
        return {}

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