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

  Supports Grandstream wireless access points.

  Supported devices:
  - GWN7600 Series
  - GWN7610
  - GWN7615
  - GWN7660
  - GWN7664
  """

  @behaviour Towerops.Snmp.Profiles.Vendors.Vendor

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

  # Grandstream Enterprise OID: 1.3.6.1.4.1.42397
  @model_oid "1.3.6.1.4.1.42397.1.1.2.1.0"

  @impl true
  def profile_names do
    ["grandstream-ap"]
  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
    [
      # Total Connected Clients
      %{
        oid: "1.3.6.1.4.1.42397.1.1.3.1.0",
        sensor_type: "clients",
        sensor_descr: "Connected Clients",
        sensor_unit: "",
        sensor_divisor: 1
      },
      # 2.4GHz Clients
      %{
        oid: "1.3.6.1.4.1.42397.1.1.3.2.0",
        sensor_type: "clients",
        sensor_descr: "2.4GHz Clients",
        sensor_unit: "",
        sensor_divisor: 1
      },
      # 5GHz Clients
      %{
        oid: "1.3.6.1.4.1.42397.1.1.3.3.0",
        sensor_type: "clients",
        sensor_descr: "5GHz Clients",
        sensor_unit: "",
        sensor_divisor: 1
      },
      # CPU Utilization
      %{
        oid: "1.3.6.1.4.1.42397.1.1.4.1.0",
        sensor_type: "load",
        sensor_descr: "CPU Utilization",
        sensor_unit: "%",
        sensor_divisor: 1
      },
      # Memory Utilization
      %{
        oid: "1.3.6.1.4.1.42397.1.1.4.2.0",
        sensor_type: "load",
        sensor_descr: "Memory Utilization",
        sensor_unit: "%",
        sensor_divisor: 1
      }
    ]
  end
end
