defmodule Towerops.Snmp.Profiles.Vendors.Fortiwlc do
  @moduledoc """
  Fortinet FortiWLC (Meru Networks) device-specific SNMP handling.

  Supports FortiWLC wireless LAN controllers (formerly Meru Networks).

  Supported devices:
  - FortiWLC 50D/100D/200D/500D
  - FortiWLC 1000D/3000D

  Enterprise OID: 1.3.6.1.4.1.15983
  """

  @behaviour Towerops.Snmp.Profiles.Vendors.Vendor

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

  # Meru/FortiWLC model OID
  @model_oid "1.3.6.1.4.1.15983.1.1.3.1.1.1.0"

  @impl true
  def profile_names, do: ["fortiwlc"]

  @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 Wireless Stations (clients)
      # MERU-GLOBAL-STATISTIC-MIB::mwSystemGeneralTotalWirelessStations.0
      %{
        oid: "1.3.6.1.4.1.15983.1.1.3.1.13.11.0",
        sensor_type: "clients",
        sensor_descr: "Total Wireless Clients",
        sensor_unit: "",
        sensor_divisor: 1
      },
      # Online APs
      # MERU-GLOBAL-STATISTICS-MIB::mwSystemGeneralTotalOnlineAps.0
      %{
        oid: "1.3.6.1.4.1.15983.1.1.3.1.13.9.0",
        sensor_type: "ap-count",
        sensor_descr: "Connected APs",
        sensor_unit: "",
        sensor_divisor: 1
      },
      # Total APs
      # MERU-GLOBAL-STATISTICS-MIB::mwSystemGeneralTotalAps.0
      %{
        oid: "1.3.6.1.4.1.15983.1.1.3.1.13.8.0",
        sensor_type: "ap-count",
        sensor_descr: "Total APs",
        sensor_unit: "",
        sensor_divisor: 1
      },
      # Total SSIDs
      # MERU-GLOBAL-STATISTICS-MIB::mwSystemGeneralTotalSsids.0
      %{
        oid: "1.3.6.1.4.1.15983.1.1.3.1.13.10.0",
        sensor_type: "count",
        sensor_descr: "Active SSIDs",
        sensor_unit: "",
        sensor_divisor: 1
      }
    ]
  end
end
