%%%-------------------------------------------------------------------
%% @doc endpoint top level supervisor.
%% @end
%%%-------------------------------------------------------------------

-module(endpoint_sup).

-behaviour(supervisor).
-include("endpoint.hrl").

-export([start_link/0]).
-export([init/1]).

-define(SERVER, ?MODULE).

start_link() ->
    supervisor:start_link({local, ?SERVER}, ?MODULE, []).

%% sup_flags() = #{strategy => strategy(),         % optional
%%                 intensity => non_neg_integer(), % optional
%%                 period => pos_integer()}        % optional
%% child_spec() = #{id => child_id(),       % mandatory
%%                  start => mfargs(),      % mandatory
%%                  restart => restart(),   % optional
%%                  shutdown => shutdown(), % optional
%%                  type => worker(),       % optional
%%                  modules => modules()}   % optional
init([]) ->
    SupFlags = #{strategy => one_for_all, intensity => 1000, period => 3600},
    ChildSpecs = [
        #{
            id => endpoint_log,
            start => {'endpoint_log', start_link, []},
            restart => permanent,
            shutdown => 2000,
            type => worker,
            modules => ['endpoint_log']
        },

        #{
            id => endpoint_subscription,
            start => {'endpoint_subscription', start_link, []},
            restart => permanent,
            shutdown => 2000,
            type => worker,
            modules => ['endpoint_subscription']
        },

        #{
            id => 'endpoint_adapter_sup',
            start => {'endpoint_adapter_sup', start_link, []},
            restart => permanent,
            shutdown => 2000,
            type => supervisor,
            modules => ['endpoint_adapter_sup']
        }
    ],
    {ok, {SupFlags, ChildSpecs}}.
