defmodule Towerops.Snmp.Profiles.Vendors.Ruckus do
  @moduledoc """
  Ruckus Wireless device-specific SNMP handling.

  Supports ZoneDirector (ZD), SmartZone (SZ), and Unleashed controllers.

  Supported devices:
  - ZoneDirector 1000/1100/1200/3000/5000
  - SmartZone 100/144/300
  - Virtual SmartZone
  - Unleashed APs
  """

  @behaviour Towerops.Snmp.Profiles.Vendors.Vendor

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

  # ZoneDirector System MIB OIDs
  # 1.3.6.1.4.1.25053.1.2.1.1.1 = ruckusZDSystemObjects
  @zd_system_model "1.3.6.1.4.1.25053.1.2.1.1.1.1.9.0"

  @impl true
  def profile_names do
    ["ruckuswireless", "ruckuswireless-sz", "ruckuswireless-unleashed", "ruckuswireless-hotzone"]
  end

  @impl true
  def detect_hardware(client_opts) do
    case Client.get(client_opts, @zd_system_model) 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
    [
      # ZoneDirector System Stats
      # Number of connected APs
      %{
        oid: "1.3.6.1.4.1.25053.1.2.1.1.1.15.1.0",
        sensor_type: "ap-count",
        sensor_descr: "Connected APs",
        sensor_unit: "",
        sensor_divisor: 1
      },
      # Number of authorized clients
      %{
        oid: "1.3.6.1.4.1.25053.1.2.1.1.1.15.2.0",
        sensor_type: "clients",
        sensor_descr: "Wireless Clients",
        sensor_unit: "",
        sensor_divisor: 1
      },
      # Number of registered APs
      %{
        oid: "1.3.6.1.4.1.25053.1.2.1.1.1.15.15.0",
        sensor_type: "ap-count",
        sensor_descr: "Registered APs",
        sensor_unit: "",
        sensor_divisor: 1
      },
      # Number of rogue APs detected
      %{
        oid: "1.3.6.1.4.1.25053.1.2.1.1.1.15.3.0",
        sensor_type: "count",
        sensor_descr: "Rogue APs",
        sensor_unit: "",
        sensor_divisor: 1
      }
    ]
  end
end
