"""Python driver for direct USB control of LibreVNA (protocol v14)."""

import logging

from .enums import (
    HardwareFamily,
    PacketType,
    SParameter,
    SweepKind,
    SweepScale,
    SyncMode,
)
from .logging_utils import DEFAULT_LOG_LEVEL, configure_logging
from .exceptions import (
    CRCError,
    DeviceDisconnectedError,
    IncompleteSweepError,
    LibreVNAError,
    NackError,
    ParseError,
    ProtocolVersionMismatch,
    TimeoutError,
    UnsupportedHardwareError,
)
from .models import (
    DeviceConfigVariant,
    DeviceInfo,
    DeviceLimits,
    DeviceStatus,
    GeneratorSettings,
    Packet,
    StreamHandle,
    SweepResult,
    USBDeviceDescriptor,
    VNADatapointPacket,
    VNARawPoint,
    VNASweepSettings,
)

__all__ = [
    "CRCError",
    "DEFAULT_LOG_LEVEL",
    "DeviceConfigVariant",
    "DeviceDisconnectedError",
    "DeviceInfo",
    "DeviceLimits",
    "DeviceStatus",
    "GeneratorSettings",
    "HardwareFamily",
    "IncompleteSweepError",
    "LibreVNADevice",
    "LibreVNAError",
    "NackError",
    "Packet",
    "PacketType",
    "ParseError",
    "ProtocolVersionMismatch",
    "configure_logging",
    "SParameter",
    "StreamHandle",
    "SweepKind",
    "SweepResult",
    "SweepScale",
    "SyncMode",
    "TimeoutError",
    "USBDeviceDescriptor",
    "UnsupportedHardwareError",
    "VNADatapointPacket",
    "VNARawPoint",
    "VNASweepSettings",
]


def __getattr__(name: str):
    """Load USB-backed device class only when native hardware access is requested."""
    if name == "LibreVNADevice":
        from .device import LibreVNADevice

        return LibreVNADevice
    raise AttributeError(name)


logging.getLogger(__name__).addHandler(logging.NullHandler())
