defmodule Towerops.Snmp.Profiles.Vendors.Cmm do
  @moduledoc """
  Cambium CMM (Cluster Management Module) device-specific SNMP handling.

  Supports Cambium Networks CMM devices for tower site management.

  Supported devices:
  - CMM3 (legacy)
  - CMM4 (current generation)
  - CMM5 (latest)
  """

  @behaviour Towerops.Snmp.Profiles.Vendors.Vendor

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

  # Cambium Enterprise OID: 1.3.6.1.4.1.161.19
  @model_oid "1.3.6.1.4.1.161.19.3.4.4.2.0"

  @impl true
  def profile_names, do: ["cmm", "cmm4"]

  @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
    [
      # Power Status (main supply)
      %{
        oid: "1.3.6.1.4.1.161.19.3.4.4.1.0",
        sensor_type: "state",
        sensor_descr: "Power Status",
        sensor_unit: "",
        sensor_divisor: 1
      },
      # GPS Sync Status
      %{
        oid: "1.3.6.1.4.1.161.19.3.4.4.3.0",
        sensor_type: "state",
        sensor_descr: "GPS Sync Status",
        sensor_unit: "",
        sensor_divisor: 1
      },
      # System Uptime (seconds)
      %{
        oid: "1.3.6.1.4.1.161.19.3.4.4.4.0",
        sensor_type: "runtime",
        sensor_descr: "System Uptime",
        sensor_unit: "s",
        sensor_divisor: 1
      },
      # Connected APs count
      %{
        oid: "1.3.6.1.4.1.161.19.3.4.4.5.0",
        sensor_type: "ap-count",
        sensor_descr: "Connected APs",
        sensor_unit: "",
        sensor_divisor: 1
      }
    ]
  end
end
