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

  Supports RUTX and RUT series LTE/cellular routers.

  Supported devices:
  - RUTX08, RUTX09, RUTX10, RUTX11, RUTX12, RUTX14, RUTX50
  - RUT200, RUT240, RUT241, RUT360
  - RUT950, RUT955, RUT956
  - TRB140, TRB145, TRB255, TRB500
  """

  @behaviour Towerops.Snmp.Profiles.Vendors.Vendor

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

  # Teltonika Enterprise OID: 1.3.6.1.4.1.48690
  @model_oid "1.3.6.1.4.1.48690.1.3.0"

  @impl true
  def profile_names do
    ["rutos-rutx", "rutos-rutm"]
  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
    [
      # Mobile Signal Strength (RSSI)
      %{
        oid: "1.3.6.1.4.1.48690.2.2.1.7.1",
        sensor_type: "rssi",
        sensor_descr: "Mobile Signal (RSSI)",
        sensor_unit: "dBm",
        sensor_divisor: 1
      },
      # Mobile RSRP (Reference Signal Received Power)
      %{
        oid: "1.3.6.1.4.1.48690.2.2.1.8.1",
        sensor_type: "rssi",
        sensor_descr: "RSRP",
        sensor_unit: "dBm",
        sensor_divisor: 1
      },
      # Mobile RSRQ (Reference Signal Received Quality)
      %{
        oid: "1.3.6.1.4.1.48690.2.2.1.10.1",
        sensor_type: "quality",
        sensor_descr: "RSRQ",
        sensor_unit: "dB",
        sensor_divisor: 1
      },
      # Mobile SINR (Signal to Interference plus Noise Ratio)
      %{
        oid: "1.3.6.1.4.1.48690.2.2.1.9.1",
        sensor_type: "snr",
        sensor_descr: "SINR",
        sensor_unit: "dB",
        sensor_divisor: 1
      },
      # Connection Type (LTE/3G/2G)
      %{
        oid: "1.3.6.1.4.1.48690.2.2.1.3.1",
        sensor_type: "state",
        sensor_descr: "Connection Type",
        sensor_unit: "",
        sensor_divisor: 1
      },
      # SIM Card Status
      %{
        oid: "1.3.6.1.4.1.48690.2.2.1.2.1",
        sensor_type: "state",
        sensor_descr: "SIM Status",
        sensor_unit: "",
        sensor_divisor: 1
      },
      # Mobile Network Operator
      %{
        oid: "1.3.6.1.4.1.48690.2.2.1.4.1",
        sensor_type: "state",
        sensor_descr: "Network Operator",
        sensor_unit: "",
        sensor_divisor: 1
      },
      # Device Temperature
      %{
        oid: "1.3.6.1.4.1.48690.1.7.0",
        sensor_type: "temperature",
        sensor_descr: "Device Temperature",
        sensor_unit: "C",
        sensor_divisor: 10
      }
    ]
  end
end
