defmodule Towerops.Snmp.Profiles.Vendors.CambiumPtp do
  @moduledoc """
  Cambium PTP (Point-to-Point) device-specific SNMP handling.

  Supports Cambium licensed and unlicensed PTP backhaul radios.

  Supported devices:
  - PTP 250
  - PTP 450/450i
  - PTP 550
  - PTP 600
  - PTP 650
  - PTP 670
  - PTP 700
  - PTP 800
  """

  @behaviour Towerops.Snmp.Profiles.Vendors.Vendor

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

  # Cambium PTP Enterprise OID: 1.3.6.1.4.1.17713
  # PTP 650/670 use .7, others may vary
  @model_oid "1.3.6.1.4.1.17713.7.1.1.0"

  @impl true
  def profile_names do
    ["ptp250", "ptp450", "ptp500", "ptp550", "ptp600", "ptp650", "ptp670", "ptp700", "ptp800"]
  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
    [
      # Receive Power (RSL)
      %{
        oid: "1.3.6.1.4.1.17713.7.12.6.0",
        sensor_type: "rssi",
        sensor_descr: "Receive Power",
        sensor_unit: "dBm",
        sensor_divisor: 10
      },
      # Transmit Power
      %{
        oid: "1.3.6.1.4.1.17713.7.12.3.0",
        sensor_type: "power",
        sensor_descr: "Transmit Power",
        sensor_unit: "dBm",
        sensor_divisor: 10
      },
      # Vector Error
      %{
        oid: "1.3.6.1.4.1.17713.7.12.8.0",
        sensor_type: "snr",
        sensor_descr: "Vector Error",
        sensor_unit: "dB",
        sensor_divisor: 10
      },
      # Link Loss
      %{
        oid: "1.3.6.1.4.1.17713.7.12.9.0",
        sensor_type: "quality",
        sensor_descr: "Link Loss",
        sensor_unit: "dB",
        sensor_divisor: 10
      },
      # Receive Data Rate
      %{
        oid: "1.3.6.1.4.1.17713.7.12.14.0",
        sensor_type: "capacity",
        sensor_descr: "Rx Data Rate",
        sensor_unit: "kbps",
        sensor_divisor: 1
      },
      # Transmit Data Rate
      %{
        oid: "1.3.6.1.4.1.17713.7.12.15.0",
        sensor_type: "capacity",
        sensor_descr: "Tx Data Rate",
        sensor_unit: "kbps",
        sensor_divisor: 1
      },
      # Radio Temperature
      %{
        oid: "1.3.6.1.4.1.17713.7.13.1.0",
        sensor_type: "temperature",
        sensor_descr: "Radio Temperature",
        sensor_unit: "C",
        sensor_divisor: 1
      }
    ]
  end
end
