defmodule Towerops.Snmp.Profiles.Vendors.Ceragon do
  @moduledoc """
  Ceragon CeraOS microwave backhaul device-specific SNMP handling.

  Supports Ceragon FibeAir microwave radio systems.

  Supported devices:
  - FibeAir IP-10 series
  - FibeAir IP-20 series
  - FibeAir RFU-C/H series
  """

  @behaviour Towerops.Snmp.Profiles.Vendors.Vendor

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

  # Ceragon Enterprise OID: 1.3.6.1.4.1.2281
  @model_oid "1.3.6.1.4.1.2281.1.1.1.0"

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

  @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
    [
      # TX Power
      %{
        oid: "1.3.6.1.4.1.2281.10.4.1.11.1.1.1",
        sensor_type: "power",
        sensor_descr: "TX Power",
        sensor_unit: "dBm",
        sensor_divisor: 10
      },
      # RX Level
      %{
        oid: "1.3.6.1.4.1.2281.10.4.1.11.1.2.1",
        sensor_type: "rssi",
        sensor_descr: "RX Level",
        sensor_unit: "dBm",
        sensor_divisor: 10
      },
      # SNR
      %{
        oid: "1.3.6.1.4.1.2281.10.4.1.11.1.3.1",
        sensor_type: "snr",
        sensor_descr: "Signal to Noise Ratio",
        sensor_unit: "dB",
        sensor_divisor: 10
      },
      # Link Status (1=up, 2=down)
      %{
        oid: "1.3.6.1.4.1.2281.10.4.1.11.1.4.1",
        sensor_type: "state",
        sensor_descr: "Link Status",
        sensor_unit: "",
        sensor_divisor: 1
      }
    ]
  end
end
