defmodule Towerops.Snmp.Profiles.Vendors.Aviat do
  @moduledoc """
  Aviat Networks (formerly Harris Stratex) device-specific SNMP handling.

  Supports WTM series microwave radios.

  Supported devices:
  - WTM 3200
  - WTM 3300
  - WTM 4000
  - WTM 4100
  - WTM 4200
  - WTM 4500
  - WTM 4800
  - CTR 8540
  """

  @behaviour Towerops.Snmp.Profiles.Vendors.Vendor

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

  # Aviat WTM MIB - System Info
  # Enterprise OID: 1.3.6.1.4.1.2509
  @model_oid "1.3.6.1.4.1.2509.9.6.1.1.2.1.3.1"

  @impl true
  def profile_names do
    ["aviat-wtm"]
  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
    [
      # Radio Temperature
      %{
        oid: "1.3.6.1.4.1.2509.9.6.2.3.1.1.5.1",
        sensor_type: "temperature",
        sensor_descr: "ODU Temperature",
        sensor_unit: "C",
        sensor_divisor: 1
      },
      # RSL (Receive Signal Level)
      %{
        oid: "1.3.6.1.4.1.2509.9.6.2.2.1.1.7.1",
        sensor_type: "rssi",
        sensor_descr: "RSL",
        sensor_unit: "dBm",
        sensor_divisor: 10
      },
      # Transmit Power
      %{
        oid: "1.3.6.1.4.1.2509.9.6.2.2.1.1.5.1",
        sensor_type: "power",
        sensor_descr: "Tx Power",
        sensor_unit: "dBm",
        sensor_divisor: 10
      },
      # Modem SNR
      %{
        oid: "1.3.6.1.4.1.2509.9.6.2.2.1.1.12.1",
        sensor_type: "snr",
        sensor_descr: "SNR",
        sensor_unit: "dB",
        sensor_divisor: 10
      },
      # Link Capacity (Mbps)
      %{
        oid: "1.3.6.1.4.1.2509.9.6.2.2.1.1.15.1",
        sensor_type: "capacity",
        sensor_descr: "Link Capacity",
        sensor_unit: "Mbps",
        sensor_divisor: 1
      }
    ]
  end
end
