# `Snakepit.Bridge.Session`
[🔗](https://github.com/nshkrdotcom/snakepit/blob/v0.13.0/lib/snakepit/bridge/session.ex#L1)

Session data structure for centralized session management.

Stores program metadata and session state for worker affinity.

# `t`

```elixir
@type t() :: %Snakepit.Bridge.Session{
  created_at: integer(),
  id: String.t(),
  last_accessed: integer(),
  last_worker_id: String.t() | nil,
  metadata: map(),
  programs: map(),
  stats: map(),
  ttl: integer()
}
```

# `delete_program`

```elixir
@spec delete_program(t(), String.t()) :: t()
```

Removes a program from the session.

## Parameters

- `session` - The session to update
- `program_id` - The program identifier to remove

## Returns

Updated session with the program removed.

# `expired?`

```elixir
@spec expired?(t(), integer() | nil) :: boolean()
```

Checks if a session has expired based on its TTL.

## Parameters

- `session` - The session to check
- `current_time` - Optional current time (defaults to current monotonic time)

## Returns

`true` if the session has expired, `false` otherwise.

# `get_metadata`

```elixir
@spec get_metadata(t(), term(), term()) :: term()
```

Gets metadata from the session.

## Parameters

- `session` - The session to query
- `key` - The metadata key
- `default` - Default value if key not found

## Returns

The metadata value or the default.

# `get_program`

```elixir
@spec get_program(t(), String.t()) :: {:ok, term()} | {:error, :not_found}
```

Gets a program from the session.

## Parameters

- `session` - The session to query
- `program_id` - The program identifier

## Returns

`{:ok, program_data}` if found, `{:error, :not_found}` if not found.

# `get_stats`

```elixir
@spec get_stats(t()) :: map()
```

Gets session statistics.

# `new`

```elixir
@spec new(
  String.t(),
  keyword()
) :: t()
```

Creates a new session with the given ID and options.

# `put_metadata`

```elixir
@spec put_metadata(t(), term(), term()) :: t()
```

Updates session metadata.

## Parameters

- `session` - The session to update
- `key` - The metadata key
- `value` - The metadata value

## Returns

Updated session with the metadata updated.

# `put_program`

```elixir
@spec put_program(t(), String.t(), term()) :: t()
```

Adds or updates a program in the session.

## Parameters

- `session` - The session to update
- `program_id` - The program identifier
- `program_data` - The program data to store

## Returns

Updated session with the program added/updated.

# `touch`

```elixir
@spec touch(t()) :: t()
```

Updates the last_accessed timestamp to the current time.

## Parameters

- `session` - The session to touch

## Returns

Updated session with current last_accessed timestamp.

# `validate`

```elixir
@spec validate(t()) :: :ok | {:error, term()}
```

Validates that a session struct has all required fields and valid data.

## Parameters

- `session` - The session to validate

## Returns

`:ok` if valid, `{:error, reason}` if invalid.

---

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