lib/runbox/scenario/template/simple.ex

defmodule Runbox.Scenario.Template.Simple do
  @moduledoc group: :internal
  @moduledoc """
  Template inspector for Simple scenario.

  Validates and provides basic information about a Simple scenario template.
  """

  @behaviour Runbox.Scenario.TemplateInspector
  alias Runbox.Scenario.Simple

  @impl true
  def valid_template?(module) do
    behaviours =
      :attributes
      |> module.module_info()
      |> Keyword.get_values(:behaviour)
      |> List.flatten()

    Enum.member?(behaviours, Runbox.Scenario.Simple)
  end

  @impl true
  def template_info(module) do
    {:ok, topics} = Simple.input_topics(module)
    %{topics: Enum.uniq(convert_topics(topics))}
  end

  defp convert_topics(topics) do
    Enum.map(topics, fn
      {topic, :input} -> {:input_topic, topic}
      {topic, :load} -> {:load_topic, topic}
      topic when is_binary(topic) -> {:input_topic, topic}
    end)
  end
end