defmodule Towerops.Snmp.Profiles.Vendors.Racom do
  @moduledoc """
  Racom RAy device-specific SNMP handling.

  Supports RAy and RAy3 microwave radios.

  Supported devices:
  - RAy series
  - RAy3 series
  """

  @behaviour Towerops.Snmp.Profiles.Vendors.Vendor

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

  # RAy MIB - product name
  @product_name_oid "1.3.6.1.4.1.33555.1.1.1.3.0"

  @impl true
  def profile_names do
    ["ray", "ray3"]
  end

  @impl true
  def detect_hardware(client_opts) do
    case Client.get(client_opts, @product_name_oid) do
      {:ok, name} when is_binary(name) -> name
      _ -> 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
    [
      # Temperature (divide by 100)
      %{
        oid: "1.3.6.1.4.1.33555.1.1.4.2.0",
        sensor_type: "temperature",
        sensor_descr: "Radio Temperature",
        sensor_unit: "C",
        sensor_divisor: 100
      },
      # Voltage (divide by 10)
      %{
        oid: "1.3.6.1.4.1.33555.1.1.4.3.0",
        sensor_type: "voltage",
        sensor_descr: "Voltage",
        sensor_unit: "V",
        sensor_divisor: 10
      },
      # BER (Bit Error Rate)
      %{
        oid: "1.3.6.1.4.1.33555.1.3.2.11.0",
        sensor_type: "ber",
        sensor_descr: "BER",
        sensor_unit: "",
        sensor_divisor: 1
      },
      # Tx Modulation Index
      %{
        oid: "1.3.6.1.4.1.33555.1.2.1.7.0",
        sensor_type: "state",
        sensor_descr: "Tx Modulation",
        sensor_unit: "",
        sensor_divisor: 1
      },
      # Rx Modulation Index
      %{
        oid: "1.3.6.1.4.1.33555.1.2.1.8.0",
        sensor_type: "state",
        sensor_descr: "Rx Modulation",
        sensor_unit: "",
        sensor_divisor: 1
      }
    ]
  end
end
