# Automatically generated by generate_types.py. Do not edit manually.
import enum

from pydantic import field_validator

from .base import CommonEntityType, load_entity_supported_types

__all__ = ["DeviceType", "DeviceTypes"]


class DeviceType(CommonEntityType):
    """
    DeviceType represents metadata for devices in Colander. Check :ref:`the list of supported types <device_types>`.

    Example:
        >>> device_type = DeviceTypes.MOBILE.value
        >>> print(device_type.name)
        Mobile device
    """

    @field_validator("short_name", mode="before")
    @classmethod
    def is_supported_type(cls, short_name: str):
        if short_name not in {t["short_name"] for t in load_entity_supported_types("device")}:
            raise ValueError(f"{short_name} is not supported")
        return short_name


class DeviceTypes(enum.Enum):
    """
    DeviceTypes provides access to all supported device types.

    This class loads device type definitions from the device types JSON file and exposes them as an enum.
    It also provides a method to look up a device type by its short name.

    Example:
        >>> device_type = DeviceTypes.LAPTOP.value
        >>> print(device_type.name)
        Laptop
        >>> default_type = DeviceTypes.by_short_name("nonexistent")
        >>> print(default_type.name)
        Generic
    """

    DESKTOP = DeviceType(
        **{
            "short_name": "DESKTOP",
            "name": "Desktop",
            "description": "A personal computer intended for regular use at a single location.",
            "icon": "",
            "nf_icon": "nf-fa-desktop",
        }
    )
    """Desktop - A personal computer intended for regular use at a single location."""

    GENERIC = DeviceType(
        **{
            "short_name": "GENERIC",
            "name": "Generic",
            "description": "A general or unspecified device type that does not fit other categories.",
            "icon": "",
            "nf_icon": "nf-fa-desktop",
        }
    )
    """Generic - A general or unspecified device type that does not fit other categories."""

    IOT = DeviceType(
        **{
            "short_name": "IOT",
            "name": "Internet of Things",
            "description": "A device connected to the internet, often embedded and used for specific functions (e.g., smart home devices).",
            "icon": "",
            "nf_icon": "nf-fa-plug",
        }
    )
    """Internet of Things - A device connected to the internet, often embedded and used for specific functions (e.g., smart home devices)."""

    LAPTOP = DeviceType(
        **{
            "short_name": "LAPTOP",
            "name": "Laptop",
            "description": "A portable personal computer designed for mobile use.",
            "icon": "",
            "nf_icon": "nf-fa-laptop",
        }
    )
    """Laptop - A portable personal computer designed for mobile use."""

    MOBILE = DeviceType(
        **{
            "short_name": "MOBILE",
            "name": "Mobile device",
            "description": "A handheld device such as a smartphone or tablet.",
            "icon": "",
            "nf_icon": "nf-fa-mobile_phone",
        }
    )
    """Mobile device - A handheld device such as a smartphone or tablet."""

    ROUTER = DeviceType(
        **{
            "short_name": "ROUTER",
            "name": "Router",
            "description": "A network device that forwards data packets between computer networks.",
            "icon": "",
            "nf_icon": "nf-mdi-router_wireless",
        }
    )
    """Router - A network device that forwards data packets between computer networks."""

    SERVER = DeviceType(
        **{
            "short_name": "SERVER",
            "name": "Server",
            "description": "A computer or system that provides resources, data, or services to other computers over a network.",
            "icon": "",
            "nf_icon": "nf-mdi-server_network",
        }
    )
    """Server - A computer or system that provides resources, data, or services to other computers over a network."""

    default = GENERIC  # type: ignore[attr-defined]

    @classmethod
    def by_short_name(cls, short_name: str):
        sn = short_name.replace(" ", "_").upper()
        if sn in cls._member_names_:
            return cls[sn].value
        return cls.default.value

    @classmethod
    def suggest(cls, value: str) -> DeviceType:
        return cls.by_short_name(value)
