defmodule Towerops.Snmp.Profiles.Vendors.Ciscowap do
  @moduledoc """
  Cisco Wireless Access Point (standalone) device-specific SNMP handling.

  Supports Cisco standalone wireless access points (not controller-managed).

  Supported devices:
  - Cisco WAP121
  - Cisco WAP321
  - Cisco WAP371
  - Cisco WAP561
  - Cisco WAP571
  - Cisco Small Business WAP Series
  """

  @behaviour Towerops.Snmp.Profiles.Vendors.Vendor

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

  # Cisco WAP uses standard Cisco enterprise OID: 1.3.6.1.4.1.9
  @model_oid "1.3.6.1.4.1.9.9.618.1.1.1.0"

  @impl true
  def profile_names do
    ["ciscowap"]
  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.9.9.618.1.8.1.0",
        sensor_type: "clients",
        sensor_descr: "Associated Clients",
        sensor_unit: "",
        sensor_divisor: 1
      },
      # 2.4GHz Channel Utilization
      %{
        oid: "1.3.6.1.4.1.9.9.618.1.4.1.1.8.1",
        sensor_type: "load",
        sensor_descr: "2.4GHz Channel Utilization",
        sensor_unit: "%",
        sensor_divisor: 1
      },
      # 5GHz Channel Utilization
      %{
        oid: "1.3.6.1.4.1.9.9.618.1.4.1.1.8.2",
        sensor_type: "load",
        sensor_descr: "5GHz Channel Utilization",
        sensor_unit: "%",
        sensor_divisor: 1
      },
      # Noise Floor 2.4GHz
      %{
        oid: "1.3.6.1.4.1.9.9.618.1.4.1.1.5.1",
        sensor_type: "noise",
        sensor_descr: "2.4GHz Noise Floor",
        sensor_unit: "dBm",
        sensor_divisor: 1
      },
      # Noise Floor 5GHz
      %{
        oid: "1.3.6.1.4.1.9.9.618.1.4.1.1.5.2",
        sensor_type: "noise",
        sensor_descr: "5GHz Noise Floor",
        sensor_unit: "dBm",
        sensor_divisor: 1
      }
    ]
  end
end
