defmodule Towerops.Snmp.Profiles.Vendors.Tranzeo do
  @moduledoc """
  Tranzeo outdoor wireless device-specific SNMP handling.

  Supports Tranzeo outdoor wireless access points and bridges.

  Supported devices:
  - Tranzeo TR-5A series
  - Tranzeo TR-5plus series
  - Tranzeo Classic series
  """

  @behaviour Towerops.Snmp.Profiles.Vendors.Vendor

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

  # Tranzeo uses sysDescr for detection
  @model_oid "1.3.6.1.2.1.1.1.0"

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

  @impl true
  def detect_hardware(client_opts) do
    case Client.get(client_opts, @model_oid) do
      {:ok, descr} when is_binary(descr) ->
        if String.contains?(descr, "Tranzeo") do
          descr
          |> String.split(" ")
          |> Enum.drop(1)
          |> Enum.take(2)
          |> Enum.join(" ")
        end

      _ ->
        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
    [
      # Associated Clients
      %{
        oid: "1.3.6.1.4.1.24350.2.1.1.0",
        sensor_type: "clients",
        sensor_descr: "Associated Clients",
        sensor_unit: "",
        sensor_divisor: 1
      },
      # Signal Strength
      %{
        oid: "1.3.6.1.4.1.24350.2.2.1.0",
        sensor_type: "rssi",
        sensor_descr: "Signal Strength",
        sensor_unit: "dBm",
        sensor_divisor: 1
      },
      # Noise Floor
      %{
        oid: "1.3.6.1.4.1.24350.2.2.2.0",
        sensor_type: "rssi",
        sensor_descr: "Noise Floor",
        sensor_unit: "dBm",
        sensor_divisor: 1
      },
      # TX Power
      %{
        oid: "1.3.6.1.4.1.24350.2.2.3.0",
        sensor_type: "power",
        sensor_descr: "TX Power",
        sensor_unit: "dBm",
        sensor_divisor: 1
      }
    ]
  end
end
