defmodule Towerops.Snmp.Profiles.Vendors.Corero do
  @moduledoc """
  SNMP profile for Corero devices.

  Auto-generated from YAML profiles. Add vendor-specific OIDs as needed.
  """

  @behaviour Towerops.Snmp.Profiles.Vendors.Vendor

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

  # Enterprise OID: 1.3.6.1.4.1.41036

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

  @impl true
  def detect_hardware(client_opts) do
    case Client.get(client_opts, "1.3.6.1.2.1.1.1.0") do
      {:ok, descr} when is_binary(descr) ->
        parse_hardware_from_descr(descr)

      _ ->
        nil
    end
  end

  defp parse_hardware_from_descr(descr) do
    # For now, return first line or word from sysDescr
    descr
    |> String.split(~r/[\r\n]/)
    |> List.first()
    |> case do
      nil -> nil
      line -> String.slice(line, 0, 64)
    end
  end

  @impl true
  def wireless_oid_defs do
    [
      # Standard HOST-RESOURCES-MIB CPU
      %{
        oid: "1.3.6.1.2.1.25.3.3.1.2.1",
        sensor_descr: "CPU Load",
        sensor_type: "load",
        sensor_unit: "%",
        sensor_divisor: 1
      }
    ]
  end

  @impl true
  def discover_wireless_sensors(client_opts) do
    Vendor.fetch_sensors(wireless_oid_defs(), client_opts)
  end
end
