defmodule Towerops.Snmp.Profiles.Vendors.Vyos do
  @moduledoc """
  VyOS and Vyatta router-specific SNMP handling.

  VyOS is an open-source network operating system based on Debian GNU/Linux.
  Vyatta is the legacy commercial predecessor to VyOS.

  Both platforms are primarily used for software routing, firewall, and VPN services.

  Supported platforms:
  - VyOS (open-source router/firewall)
  - Vyatta (legacy commercial router)
  """

  @behaviour Towerops.Snmp.Profiles.Vendors.Vendor

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

  @impl true
  def profile_names, do: ["vyos", "vyatta"]

  @impl true
  def detect_hardware(client_opts) do
    # VyOS/Vyatta hardware is detected from sysDescr
    # Version is extracted via regex in YAML profiles
    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
    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
    # VyOS/Vyatta are software routers - no hardware sensors
    # All monitoring is done via standard MIBs (IF-MIB, IP-MIB, etc.)
    []
  end

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