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

  Supports Netonix WISP switches popular in wireless ISP deployments.

  Supported devices:
  - WS-6-MINI
  - WS-8-150-AC
  - WS-12-250-AC
  - WS-12-400-AC
  - WS-12-DC
  - WS-26-400-AC
  """

  @behaviour Towerops.Snmp.Profiles.Vendors.Vendor

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

  # Netonix Enterprise OID: 1.3.6.1.4.1.46242
  @model_oid "1.3.6.1.4.1.46242.1.1.0"

  @impl true
  def profile_names do
    ["netonix"]
  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
    [
      # Board Temperature
      %{
        oid: "1.3.6.1.4.1.46242.2.1.0",
        sensor_type: "temperature",
        sensor_descr: "Board Temperature",
        sensor_unit: "C",
        sensor_divisor: 1
      },
      # CPU Temperature
      %{
        oid: "1.3.6.1.4.1.46242.2.2.0",
        sensor_type: "temperature",
        sensor_descr: "CPU Temperature",
        sensor_unit: "C",
        sensor_divisor: 1
      },
      # Fan Speed
      %{
        oid: "1.3.6.1.4.1.46242.2.3.0",
        sensor_type: "fanspeed",
        sensor_descr: "Fan Speed",
        sensor_unit: "RPM",
        sensor_divisor: 1
      },
      # PSU1 Voltage
      %{
        oid: "1.3.6.1.4.1.46242.3.1.0",
        sensor_type: "voltage",
        sensor_descr: "PSU1 Voltage",
        sensor_unit: "V",
        sensor_divisor: 1000
      },
      # PSU2 Voltage
      %{
        oid: "1.3.6.1.4.1.46242.3.2.0",
        sensor_type: "voltage",
        sensor_descr: "PSU2 Voltage",
        sensor_unit: "V",
        sensor_divisor: 1000
      },
      # Total PoE Power
      %{
        oid: "1.3.6.1.4.1.46242.4.1.0",
        sensor_type: "power",
        sensor_descr: "Total PoE Power",
        sensor_unit: "W",
        sensor_divisor: 1000
      }
    ]
  end
end
