defmodule Towerops.Snmp.Profiles.Vendors.Aruba do
  @moduledoc """
  Aruba Networks (HPE) device-specific SNMP handling.

  Supports Aruba wireless controllers and Instant APs.

  Supported devices:
  - Aruba 7000 Series Controllers
  - Aruba 7200 Series Controllers
  - Aruba Instant APs (IAP)
  - Aruba AOS-CX Switches
  """

  @behaviour Towerops.Snmp.Profiles.Vendors.Vendor

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

  # Aruba Enterprise OID: 1.3.6.1.4.1.14823
  # wlsxSwitchModel - Controller model
  @model_oid "1.3.6.1.4.1.14823.2.2.1.1.1.2.0"

  @impl true
  def profile_names do
    ["aruba-instant", "arubaos", "arubaos-cx"]
  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 Stations (Clients)
      %{
        oid: "1.3.6.1.4.1.14823.2.2.1.1.3.1.0",
        sensor_type: "clients",
        sensor_descr: "Associated Clients",
        sensor_unit: "",
        sensor_divisor: 1
      },
      # Total APs (Managed)
      %{
        oid: "1.3.6.1.4.1.14823.2.2.1.1.3.2.0",
        sensor_type: "ap-count",
        sensor_descr: "Managed APs",
        sensor_unit: "",
        sensor_divisor: 1
      },
      # Controller CPU Utilization
      %{
        oid: "1.3.6.1.4.1.14823.2.2.1.1.1.10.0",
        sensor_type: "load",
        sensor_descr: "CPU Utilization",
        sensor_unit: "%",
        sensor_divisor: 1
      },
      # Controller Memory Utilization
      %{
        oid: "1.3.6.1.4.1.14823.2.2.1.1.1.11.0",
        sensor_type: "load",
        sensor_descr: "Memory Utilization",
        sensor_unit: "%",
        sensor_divisor: 1
      },
      # Total SSIDs
      %{
        oid: "1.3.6.1.4.1.14823.2.2.1.1.3.3.0",
        sensor_type: "count",
        sensor_descr: "Active SSIDs",
        sensor_unit: "",
        sensor_divisor: 1
      }
    ]
  end
end
