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

  Supports Baicells LTE/5G equipment including eNodeBs and CPEs.

  Supported devices:
  - Nova 227 CPE
  - Nova 233 CPE
  - Nova 243 CPE
  - Atom OD04 CPE
  - Nova 436Q eNodeB
  - Nova 446 eNodeB
  """

  @behaviour Towerops.Snmp.Profiles.Vendors.Vendor

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

  # Baicells CPE MIB
  @model_oid "1.3.6.1.4.1.48290.1.1.1.0"

  @impl true
  def profile_names do
    ["baicells-od04", "baicells"]
  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
    [
      # RSRP (Reference Signal Received Power)
      %{
        oid: "1.3.6.1.4.1.48290.2.1.1.0",
        sensor_type: "rssi",
        sensor_descr: "RSRP",
        sensor_unit: "dBm",
        sensor_divisor: 1
      },
      # RSRQ (Reference Signal Received Quality)
      %{
        oid: "1.3.6.1.4.1.48290.2.1.2.0",
        sensor_type: "quality",
        sensor_descr: "RSRQ",
        sensor_unit: "dB",
        sensor_divisor: 1
      },
      # SINR (Signal to Interference plus Noise Ratio)
      %{
        oid: "1.3.6.1.4.1.48290.2.1.3.0",
        sensor_type: "snr",
        sensor_descr: "SINR",
        sensor_unit: "dB",
        sensor_divisor: 1
      },
      # RSSI
      %{
        oid: "1.3.6.1.4.1.48290.2.1.4.0",
        sensor_type: "rssi",
        sensor_descr: "RSSI",
        sensor_unit: "dBm",
        sensor_divisor: 1
      },
      # Tx Power
      %{
        oid: "1.3.6.1.4.1.48290.2.1.5.0",
        sensor_type: "power",
        sensor_descr: "Tx Power",
        sensor_unit: "dBm",
        sensor_divisor: 1
      },
      # Device Temperature
      %{
        oid: "1.3.6.1.4.1.48290.1.2.1.0",
        sensor_type: "temperature",
        sensor_descr: "Device Temperature",
        sensor_unit: "C",
        sensor_divisor: 1
      }
    ]
  end
end
