"""Enumerations used by the LibreVNA direct-USB driver."""

from __future__ import annotations

from enum import Enum, IntEnum


class PacketType(IntEnum):
    """Packet identifiers defined by LibreVNA protocol v14."""

    NONE = 0
    SWEEP_SETTINGS = 2
    MANUAL_STATUS = 3
    MANUAL_CONTROL = 4
    DEVICE_INFO = 5
    FIRMWARE_PACKET = 6
    ACK = 7
    CLEAR_FLASH = 8
    PERFORM_FIRMWARE_UPDATE = 9
    NACK = 10
    REFERENCE = 11
    GENERATOR = 12
    SPECTRUM_ANALYZER_SETTINGS = 13
    SPECTRUM_ANALYZER_RESULT = 14
    REQUEST_DEVICE_INFO = 15
    REQUEST_SOURCE_CAL = 16
    REQUEST_RECEIVER_CAL = 17
    SOURCE_CAL_POINT = 18
    RECEIVER_CAL_POINT = 19
    SET_IDLE = 20
    REQUEST_FREQUENCY_CORRECTION = 21
    FREQUENCY_CORRECTION = 22
    REQUEST_DEVICE_CONFIGURATION = 23
    DEVICE_CONFIGURATION = 24
    DEVICE_STATUS = 25
    REQUEST_DEVICE_STATUS = 26
    VNA_DATAPOINT = 27
    SET_TRIGGER = 28
    CLEAR_TRIGGER = 29
    STOP_STATUS_UPDATES = 30
    START_STATUS_UPDATES = 31
    INITIATE_SWEEP = 32
    PERFORM_ACTION = 33
    RESET_DEVICE_CONFIGURATION = 34


class SyncMode(IntEnum):
    """Synchronization mode encoded in sweep settings."""

    DISABLED = 0
    USB = 1
    EXTERNAL_REFERENCE = 2
    EXTERNAL_TRIGGER = 3


class HardwareFamily(IntEnum):
    """Known LibreVNA hardware families."""

    V1 = 0x01
    VD0 = 0xD0
    VE0 = 0xE0
    VFE = 0xFE
    VFF = 0xFF
    UNKNOWN = 0x00


class SweepKind(str, Enum):
    """Logical VNA sweep mode."""

    FREQUENCY = "frequency"
    POWER = "power"


class SweepScale(str, Enum):
    """Frequency axis spacing."""

    LIN = "lin"
    LOG = "log"


class SParameter(str, Enum):
    """Canonical 2-port S-parameters."""

    S11 = "S11"
    S12 = "S12"
    S21 = "S21"
    S22 = "S22"
