defmodule Towerops.Snmp.Profiles.Vendors.Aerohive do
  @moduledoc """
  Aerohive/Extreme Networks HiveOS device-specific SNMP handling.

  Supports Aerohive wireless access points running HiveOS or IQ Engine.

  Supported devices:
  - AP121
  - AP130
  - AP230
  - AP250
  - AP550
  - AP650/AP650X
  """

  @behaviour Towerops.Snmp.Profiles.Vendors.Vendor

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

  # Aerohive Enterprise OID: 1.3.6.1.4.1.26928
  @model_oid "1.3.6.1.4.1.26928.1.1.1.1.0"

  @impl true
  def profile_names do
    ["hiveos-wireless"]
  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 Associated Clients
      %{
        oid: "1.3.6.1.4.1.26928.1.1.1.2.1.1.0",
        sensor_type: "clients",
        sensor_descr: "Associated Clients",
        sensor_unit: "",
        sensor_divisor: 1
      },
      # 2.4GHz Clients
      %{
        oid: "1.3.6.1.4.1.26928.1.1.1.2.1.2.0",
        sensor_type: "clients",
        sensor_descr: "2.4GHz Clients",
        sensor_unit: "",
        sensor_divisor: 1
      },
      # 5GHz Clients
      %{
        oid: "1.3.6.1.4.1.26928.1.1.1.2.1.3.0",
        sensor_type: "clients",
        sensor_descr: "5GHz Clients",
        sensor_unit: "",
        sensor_divisor: 1
      },
      # CPU Utilization
      %{
        oid: "1.3.6.1.4.1.26928.1.1.1.3.1.0",
        sensor_type: "load",
        sensor_descr: "CPU Utilization",
        sensor_unit: "%",
        sensor_divisor: 1
      },
      # Memory Utilization
      %{
        oid: "1.3.6.1.4.1.26928.1.1.1.3.2.0",
        sensor_type: "load",
        sensor_descr: "Memory Utilization",
        sensor_unit: "%",
        sensor_divisor: 1
      },
      # System Temperature
      %{
        oid: "1.3.6.1.4.1.26928.1.1.1.3.3.0",
        sensor_type: "temperature",
        sensor_descr: "System Temperature",
        sensor_unit: "C",
        sensor_divisor: 1
      }
    ]
  end
end
