# `Tink.Config`
[🔗](https://github.com/iamkanishka/tink.ex/blob/v0.1.1/lib/tink/config.ex#L1)

Configuration management for Tink.

This module handles loading and validating configuration from multiple sources:

1. Application environment (config.exs)
2. System environment variables
3. Runtime options

## Configuration Options

### Required
- `:client_id` - Tink OAuth client ID
- `:client_secret` - Tink OAuth client secret (for client credentials flow)

### Optional
- `:environment` - `:production` or `:sandbox` (default: :production)
- `:base_url` - API base URL (default: based on environment)
- `:timeout` - Request timeout in ms (default: 30_000)
- `:max_retries` - Maximum retry attempts (default: 3)
- `:pool_size` - HTTP connection pool size (default: 32)
- `:enable_caching` - Enable token caching (default: true)
- `:enable_rate_limiting` - Enable rate limiting (default: true)
- `:http_client` - HTTP client module (default: Tink.HTTPAdapter)
- `:debug_mode` - Enable debug logging (default: false)

## Configuration Sources

### Application Config

    # config/config.exs
    config :tink,
      client_id: "your_client_id",
      client_secret: "your_client_secret",
      environment: :production

### System Environment Variables

    export TINK_CLIENT_ID="your_client_id"
    export TINK_CLIENT_SECRET="your_client_secret"
    export TINK_ENVIRONMENT="production"

### Runtime Options

    client = Tink.client(
      client_id: "runtime_id",
      client_secret: "runtime_secret"
    )

## Precedence

Runtime options > Environment variables > Application config > Defaults

# `base_url`

```elixir
@spec base_url() :: String.t()
```

Gets the base URL for the configured environment.

## Examples

    iex> Tink.Config.base_url()
    "https://api.tink.com"

# `build_client_config`

```elixir
@spec build_client_config(keyword()) :: map()
```

Builds client configuration from options.

Merges provided options with application configuration.

## Examples

    iex> Tink.Config.build_client_config(client_id: "custom_id")
    %{client_id: "custom_id", client_secret: "...", ...}

# `caching_enabled?`

```elixir
@spec caching_enabled?() :: boolean()
```

Checks if caching is enabled.

## Examples

    iex> Tink.Config.caching_enabled?()
    true

# `debug_mode?`

```elixir
@spec debug_mode?() :: boolean()
```

Checks if debug mode is enabled.

# `get`

```elixir
@spec get(atom(), term()) :: term()
```

Gets a configuration value.

Checks in order:
1. Application environment
2. System environment variable
3. Default value (if provided)

## Examples

    iex> Tink.Config.get(:client_id)
    "your_client_id"

    iex> Tink.Config.get(:timeout, 5000)
    30000

# `get_all`

```elixir
@spec get_all() :: keyword()
```

Gets all configuration as a keyword list.

## Examples

    iex> Tink.Config.get_all()
    [
      client_id: "your_id",
      client_secret: "your_secret",
      environment: :production,
      ...
    ]

# `rate_limiting_enabled?`

```elixir
@spec rate_limiting_enabled?() :: boolean()
```

Checks if rate limiting is enabled.

Reads the flat `:enable_rate_limiting` key set by `config/runtime.exs`.

# `validate`

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

Validates the current configuration.

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

## Examples

    iex> Tink.Config.validate()
    :ok

    iex> Tink.Config.validate()
    {:error, "Missing required configuration: client_id"}

---

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