defmodule Towerops.Snmp.Profiles.Vendors.Fortiap do
  @moduledoc """
  Fortinet FortiAP device-specific SNMP handling.

  Supports FortiAP wireless access points.

  Supported devices:
  - FortiAP series (221E, 231F, 431F, etc.)
  - FortiAP-S series
  - FortiAP-U series
  """

  @behaviour Towerops.Snmp.Profiles.Vendors.Vendor

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

  # Fortinet Enterprise OID: 1.3.6.1.4.1.12356
  @model_oid "1.3.6.1.4.1.12356.120.10.1.1.0"

  @impl true
  def profile_names, do: ["fortiap"]

  @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 Associated Clients
      %{
        oid: "1.3.6.1.4.1.12356.120.10.2.1.0",
        sensor_type: "clients",
        sensor_descr: "Associated Clients",
        sensor_unit: "",
        sensor_divisor: 1
      },
      # CPU Utilization
      %{
        oid: "1.3.6.1.4.1.12356.120.10.3.1.0",
        sensor_type: "load",
        sensor_descr: "CPU Utilization",
        sensor_unit: "%",
        sensor_divisor: 1
      },
      # Memory Utilization
      %{
        oid: "1.3.6.1.4.1.12356.120.10.3.2.0",
        sensor_type: "load",
        sensor_descr: "Memory Utilization",
        sensor_unit: "%",
        sensor_divisor: 1
      },
      # 2.4GHz Radio Clients
      %{
        oid: "1.3.6.1.4.1.12356.120.10.2.2.0",
        sensor_type: "clients",
        sensor_descr: "2.4GHz Clients",
        sensor_unit: "",
        sensor_divisor: 1
      },
      # 5GHz Radio Clients
      %{
        oid: "1.3.6.1.4.1.12356.120.10.2.3.0",
        sensor_type: "clients",
        sensor_descr: "5GHz Clients",
        sensor_unit: "",
        sensor_divisor: 1
      }
    ]
  end
end
