defmodule Prymn.Agents.Supervisor do
  @moduledoc false

  use Supervisor

  @dynamic_supervisor Prymn.Agents.ConnectionSupervisor

  def start_link(init_arg) do
    Supervisor.start_link(__MODULE__, init_arg, name: __MODULE__)
  end

  @impl true
  def init(_init_arg) do
    children = [
      # The registry will be used to register `Connection` processes with their
      # name as their address
      {Registry, keys: :unique, name: Prymn.Agents.Registry},
      # Dynamically start `Connection` processes
      {DynamicSupervisor, name: @dynamic_supervisor, strategy: :one_for_one, max_seconds: 60}
    ]

    # Register a "health" table that stores in-memory any agent health data
    Prymn.Agents.Health.start()

    Supervisor.init(children, strategy: :one_for_one)
  end
end