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

  Supports Calix GPON/fiber access equipment.

  Supported devices:
  - Calix E7-2 AXOS systems
  - Calix E7 EXA nodes
  - Calix C7 platforms
  - Calix GigaSpire/GigaPoint ONTs

  Enterprise OID: 1.3.6.1.4.1.6321
  """

  @behaviour Towerops.Snmp.Profiles.Vendors.Vendor

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

  # Calix system description
  @sysdescr_oid "1.3.6.1.2.1.1.1.0"

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

  @impl true
  def detect_hardware(client_opts) do
    # Calix model typically in sysDescr
    case Client.get(client_opts, @sysdescr_oid) do
      {:ok, descr} when is_binary(descr) ->
        cond do
          String.contains?(descr, "E7-2") -> "E7-2"
          String.contains?(descr, "E7") -> "E7"
          String.contains?(descr, "C7") -> "C7"
          String.contains?(descr, "AXOS") -> "AXOS"
          true -> nil
        end

      _ ->
        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
    # Calix GPON OIDs are not publicly documented
    # Using standard MIB OIDs for basic system metrics
    [
      # CPU Load (HOST-RESOURCES-MIB)
      %{
        oid: "1.3.6.1.2.1.25.3.3.1.2.1",
        sensor_type: "load",
        sensor_descr: "CPU Load",
        sensor_unit: "%",
        sensor_divisor: 1
      },
      # System Uptime
      %{
        oid: "1.3.6.1.2.1.1.3.0",
        sensor_type: "count",
        sensor_descr: "System Uptime",
        sensor_unit: "ticks",
        sensor_divisor: 1
      }
    ]
  end
end
