defmodule Towerops.Snmp.Profiles.Vendors.Engenius do
  @moduledoc """
  EnGenius device-specific SNMP handling.

  Supports EnGenius wireless access points and outdoor equipment.

  Supported devices:
  - ENS Series (ENS500, ENS620EXT)
  - EWS Series (EWS357AP, EWS377AP)
  - ECW Series (ECW230, ECW260)
  - EnStationAC
  - EnJet Series
  """

  @behaviour Towerops.Snmp.Profiles.Vendors.Vendor

  alias Towerops.Snmp.Client
  alias Towerops.Snmp.Profiles.Vendors.Vendor

  # EnGenius Enterprise OID: 1.3.6.1.4.1.14125
  @model_oid "1.3.6.1.4.1.14125.1.1.1.0"

  @impl true
  def profile_names do
    ["engenius"]
  end

  @impl true
  def detect_hardware(client_opts) do
    case Client.get(client_opts, @model_oid) do
      {:ok, model} when is_binary(model) -> model
      _ -> nil
    end
  end

  @impl true
  def discover_wireless_sensors(client_opts) do
    Vendor.fetch_sensors(wireless_oid_defs(), client_opts)
  end

  @impl true
  def wireless_oid_defs do
    [
      # Total Connected Clients
      %{
        oid: "1.3.6.1.4.1.14125.100.1.4.1.0",
        sensor_type: "clients",
        sensor_descr: "Connected Clients",
        sensor_unit: "",
        sensor_divisor: 1
      },
      # 2.4GHz Clients
      %{
        oid: "1.3.6.1.4.1.14125.100.1.4.2.0",
        sensor_type: "clients",
        sensor_descr: "2.4GHz Clients",
        sensor_unit: "",
        sensor_divisor: 1
      },
      # 5GHz Clients
      %{
        oid: "1.3.6.1.4.1.14125.100.1.4.3.0",
        sensor_type: "clients",
        sensor_descr: "5GHz Clients",
        sensor_unit: "",
        sensor_divisor: 1
      },
      # CPU Utilization
      %{
        oid: "1.3.6.1.4.1.14125.100.1.5.1.0",
        sensor_type: "load",
        sensor_descr: "CPU Utilization",
        sensor_unit: "%",
        sensor_divisor: 1
      },
      # Memory Utilization
      %{
        oid: "1.3.6.1.4.1.14125.100.1.5.2.0",
        sensor_type: "load",
        sensor_descr: "Memory Utilization",
        sensor_unit: "%",
        sensor_divisor: 1
      },
      # Channel Utilization 2.4GHz
      %{
        oid: "1.3.6.1.4.1.14125.100.1.6.1.0",
        sensor_type: "load",
        sensor_descr: "2.4GHz Channel Utilization",
        sensor_unit: "%",
        sensor_divisor: 1
      },
      # Channel Utilization 5GHz
      %{
        oid: "1.3.6.1.4.1.14125.100.1.6.2.0",
        sensor_type: "load",
        sensor_descr: "5GHz Channel Utilization",
        sensor_unit: "%",
        sensor_divisor: 1
      }
    ]
  end
end
