defmodule Towerops.Snmp.Profiles.Vendors.Cnmatrix do
  @moduledoc """
  Cambium cnMatrix device-specific SNMP handling.

  Supports Cambium cnMatrix managed Ethernet switches.

  Supported devices:
  - cnMatrix EX1010
  - cnMatrix EX1028
  - cnMatrix EX2010
  - cnMatrix EX2028
  - cnMatrix TX1012
  - cnMatrix TX2012
  """

  @behaviour Towerops.Snmp.Profiles.Vendors.Vendor

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

  # Cambium cnMatrix Enterprise OID: 1.3.6.1.4.1.17713.24
  @model_oid "1.3.6.1.4.1.17713.24.1.1.1.0"

  @impl true
  def profile_names do
    ["cnmatrix"]
  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
    [
      # CPU Utilization
      %{
        oid: "1.3.6.1.4.1.17713.24.2.1.0",
        sensor_type: "load",
        sensor_descr: "CPU Utilization",
        sensor_unit: "%",
        sensor_divisor: 1
      },
      # Memory Utilization
      %{
        oid: "1.3.6.1.4.1.17713.24.2.2.0",
        sensor_type: "load",
        sensor_descr: "Memory Utilization",
        sensor_unit: "%",
        sensor_divisor: 1
      },
      # System Temperature
      %{
        oid: "1.3.6.1.4.1.17713.24.3.1.0",
        sensor_type: "temperature",
        sensor_descr: "System Temperature",
        sensor_unit: "C",
        sensor_divisor: 1
      },
      # Fan Speed
      %{
        oid: "1.3.6.1.4.1.17713.24.3.2.0",
        sensor_type: "fanspeed",
        sensor_descr: "Fan Speed",
        sensor_unit: "RPM",
        sensor_divisor: 1
      },
      # Total PoE Power
      %{
        oid: "1.3.6.1.4.1.17713.24.4.1.0",
        sensor_type: "power",
        sensor_descr: "Total PoE Power",
        sensor_unit: "W",
        sensor_divisor: 1000
      }
    ]
  end
end
