# `ExWapp.Session.Supervisor`
[🔗](https://github.com/elchemista/ex_wapp/blob/v0.1.5/lib/ex_wapp/session/supervisor.ex#L1)

DynamicSupervisor for managing multiple WhatsApp sessions.

This supervisor can start, stop, and manage multiple sessions dynamically.
Each session is identified by a unique session ID and can be looked up
via the built-in Registry.

## Starting the Supervisor

Add to your application supervision tree:

    children = [
      ExWapp.Session.Supervisor
    ]

    Supervisor.start_link(children, strategy: :one_for_one)

Or start manually:

    {:ok, _pid} = ExWapp.Session.Supervisor.start_link()

## Managing Sessions

    # Start a new session
    {:ok, session} = ExWapp.Session.Supervisor.start_session("user_123",
      store: {ExWapp.Store.Ets, path: "/data/user_123.etf"}
    )

    # Look up an existing session
    {:ok, session} = ExWapp.Session.Supervisor.get_session("user_123")

    # List all sessions
    sessions = ExWapp.Session.Supervisor.list_sessions()
    #=> [{"user_123", #PID<0.234.0>}, {"user_456", #PID<0.267.0>}]

    # Stop a session
    :ok = ExWapp.Session.Supervisor.stop_session("user_123")

## Session IDs

Session IDs can be any term but strings are recommended. Common patterns:
- User ID: `"user_123"`
- Phone number: `"+1234567890"`
- UUID: `"550e8400-e29b-41d4-a716-446655440000"`

# `child_spec`

Returns the child specification for use in a supervision tree.

# `count_sessions`

```elixir
@spec count_sessions() :: non_neg_integer()
```

Returns the count of active sessions.

# `get_live_sessions`

```elixir
@spec get_live_sessions(term()) :: [pid()]
```

Returns all live session pids matching a session ID.

# `get_session`

```elixir
@spec get_session(term()) :: {:ok, pid()} | :error
```

Looks up a session by ID.

Returns `{:ok, pid}` if found, or `:error` if not found.

# `list_sessions`

```elixir
@spec list_sessions() :: [{term(), pid()}]
```

Returns a list of all active sessions.

Returns a list of `{session_id, pid}` tuples.

# `session_exists?`

```elixir
@spec session_exists?(term()) :: boolean()
```

Checks if a session exists.

# `start_link`

```elixir
@spec start_link(keyword()) :: Supervisor.on_start()
```

Starts the session supervisor.

This also starts the Registry for session lookup.

# `start_session`

```elixir
@spec start_session(term(), keyword() | ExWapp.Session.Options.t()) ::
  {:ok, pid()} | {:error, term()}
```

Starts a new session with the given ID.

Returns `{:ok, pid}` if successful, or `{:error, reason}` if the session
could not be started or already exists.

## Options

  * `:store` - Storage adapter (see `ExWapp.Store`)
  * `:auto_connect` - Connect automatically on start (default: false)
  * `:reconnect` - Enable automatic reconnection (default: true)
  * `:runtime` - Runtime hardening config override for this session

## Examples

    {:ok, session} = ExWapp.Session.Supervisor.start_session("user_123",
      store: {ExWapp.Store.Ets, path: "/data/sessions/user_123.etf"}
    )

    # With auto-connect
    {:ok, session} = ExWapp.Session.Supervisor.start_session("user_456",
      store: ExWapp.Store.Memory,
      auto_connect: true
    )

# `stop_all_sessions`

```elixir
@spec stop_all_sessions(term()) :: :ok
```

Stops all live sessions for the given ID.

# `stop_session`

```elixir
@spec stop_session(term()) :: :ok | {:error, :not_found}
```

Stops a session by ID.

Returns `:ok` if the session was stopped, or `{:error, :not_found}` if
no session with that ID exists.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
