# `Exdantic.Config`
[🔗](https://github.com/nshkrdotcom/exdantic/blob/v0.1.0/lib/exdantic/config.ex#L1)

Advanced configuration with runtime modification support.

This module provides functionality for creating and manipulating validation
configuration at runtime, supporting the DSPy pattern of dynamic config
modification like `ConfigDict(extra="forbid", frozen=True)`.

# `coercion_strategy`

```elixir
@type coercion_strategy() :: :none | :safe | :aggressive
```

# `error_format`

```elixir
@type error_format() :: :detailed | :simple | :minimal
```

# `extra_strategy`

```elixir
@type extra_strategy() :: :allow | :forbid | :ignore
```

# `t`

```elixir
@type t() :: %Exdantic.Config{
  allow_population_by_field_name: boolean(),
  case_sensitive: boolean(),
  coercion: coercion_strategy(),
  description_generator: (atom() -&gt; String.t()) | nil,
  error_format: error_format(),
  extra: extra_strategy(),
  frozen: boolean(),
  max_anyof_union_len: non_neg_integer(),
  strict: boolean(),
  title_generator: (atom() -&gt; String.t()) | nil,
  use_enum_values: boolean(),
  validate_assignment: boolean()
}
```

# `allow_extra_fields?`

```elixir
@spec allow_extra_fields?(t()) :: boolean()
```

Checks if extra fields should be allowed based on configuration.

## Parameters
  * `config` - The configuration to check

## Returns
  * `true` if extra fields are allowed, `false` otherwise

## Examples

    iex> config = Exdantic.Config.create(extra: :allow)
    iex> Exdantic.Config.allow_extra_fields?(config)
    true

    iex> config = Exdantic.Config.create(extra: :forbid)
    iex> Exdantic.Config.allow_extra_fields?(config)
    false

# `builder`

```elixir
@spec builder() :: Exdantic.Config.Builder.t()
```

Creates a builder for fluent configuration creation.

## Returns
  * ConfigBuilder struct for chaining configuration calls

## Examples

    iex> config = Exdantic.Config.builder()
    ...> |> Exdantic.Config.Builder.strict(true)
    ...> |> Exdantic.Config.Builder.forbid_extra()
    ...> |> Exdantic.Config.Builder.safe_coercion()
    ...> |> Exdantic.Config.Builder.build()
    %Exdantic.Config{strict: true, extra: :forbid, coercion: :safe, ...}

# `coercion_level`

```elixir
@spec coercion_level(t()) :: coercion_strategy()
```

Gets the coercion aggressiveness level.

## Parameters
  * `config` - The configuration to check

## Returns
  * Coercion strategy atom

## Examples

    iex> config = Exdantic.Config.create(coercion: :aggressive)
    iex> Exdantic.Config.coercion_level(config)
    :aggressive

# `create`

```elixir
@spec create(keyword() | map()) :: t()
```

Creates a new configuration with the specified options.

## Parameters
  * `opts` - Configuration options as keyword list or map

## Options
  * `:strict` - Enforce strict validation (default: false)
  * `:extra` - How to handle extra fields (default: :allow)
  * `:coercion` - Type coercion strategy (default: :safe)
  * `:frozen` - Whether the config is immutable (default: false)
  * `:validate_assignment` - Validate field assignments (default: false)
  * `:error_format` - Error format style (default: :detailed)

## Returns
  * New Config struct

## Examples

    iex> config = Exdantic.Config.create(strict: true, extra: :forbid)
    iex> config.strict
    true

    iex> config = Exdantic.Config.create(%{coercion: :aggressive, frozen: true})
    iex> config.coercion
    :aggressive

# `create_enhanced`

```elixir
@spec create_enhanced(map() | keyword()) :: t()
```

Creates a configuration optimized for Phase 6 enhanced features.

Phase 6 Enhancement: Configuration that supports all new features and LLM optimizations.

## Parameters
  * `opts` - Configuration options with Phase 6 enhancements

## Phase 6 Options
  * `:llm_provider` - Target LLM provider for optimization (:openai, :anthropic, :generic)
  * `:dspy_compatible` - Ensure DSPy compatibility (default: false)
  * `:enhanced_validation` - Enable enhanced validation pipeline (default: true)
  * `:include_metadata` - Include enhanced metadata in schemas (default: true)
  * `:performance_mode` - Optimize for performance (:speed, :memory, :balanced)

## Examples

    iex> config = Exdantic.Config.create_enhanced(%{
    ...>   llm_provider: :openai,
    ...>   dspy_compatible: true,
    ...>   performance_mode: :balanced
    ...> })
    %Exdantic.Config{...}

# `for_dspy`

```elixir
@spec for_dspy(
  :signature | :chain_of_thought | :input_output | :general,
  keyword()
) :: t()
```

Creates a preset configuration for DSPy integration.

Phase 6 Enhancement: Specialized configuration for DSPy patterns.

## Parameters
  * `dspy_mode` - DSPy usage pattern (:signature, :chain_of_thought, :input_output, :general)
  * `opts` - Additional configuration options

## Examples

    iex> config = Exdantic.Config.for_dspy(:signature, provider: :openai)
    %Exdantic.Config{strict: true, extra: :forbid, ...}

# `merge`

```elixir
@spec merge(t(), map() | keyword()) :: t()
```

Merges configuration options with an existing config.

## Parameters
  * `base_config` - The base configuration
  * `overrides` - Configuration options to merge/override

## Returns
  * New Config struct with merged options
  * Raises if base config is frozen and overrides are provided

## Examples

    iex> base = Exdantic.Config.create(strict: true)
    iex> merged = Exdantic.Config.merge(base, %{extra: :forbid, coercion: :none})
    %Exdantic.Config{strict: true, extra: :forbid, coercion: :none, ...}

    iex> frozen = Exdantic.Config.create(frozen: true)
    iex> Exdantic.Config.merge(frozen, %{strict: true})
    ** (RuntimeError) Cannot modify frozen configuration

# `preset`

```elixir
@spec preset(:strict | :lenient | :api | :json_schema | :development | :production) ::
  t()
```

Creates a preset configuration for common validation scenarios.

## Parameters
  * `preset` - The preset name

## Available Presets
  * `:strict` - Strict validation with no extra fields
  * `:lenient` - Lenient validation allowing extra fields
  * `:api` - Configuration suitable for API validation
  * `:json_schema` - Configuration optimized for JSON Schema generation
  * `:development` - Development-friendly configuration
  * `:production` - Production-ready configuration

## Returns
  * Pre-configured Config struct

## Examples

    iex> Exdantic.Config.preset(:strict)
    %Exdantic.Config{strict: true, extra: :forbid, coercion: :none, ...}

    iex> Exdantic.Config.preset(:lenient)
    %Exdantic.Config{strict: false, extra: :allow, coercion: :safe, ...}

# `should_coerce?`

```elixir
@spec should_coerce?(t()) :: boolean()
```

Checks if type coercion should be performed based on configuration.

## Parameters
  * `config` - The configuration to check

## Returns
  * `true` if coercion should be performed, `false` otherwise

## Examples

    iex> config = Exdantic.Config.create(coercion: :safe)
    iex> Exdantic.Config.should_coerce?(config)
    true

    iex> config = Exdantic.Config.create(coercion: :none)
    iex> Exdantic.Config.should_coerce?(config)
    false

# `summary`

```elixir
@spec summary(t()) :: %{
  validation_mode: String.t(),
  extra_fields: String.t(),
  coercion: String.t(),
  frozen: boolean(),
  error_format: String.t(),
  features: [String.t()]
}
```

Returns a summary of the configuration settings.

## Parameters
  * `config` - The configuration to summarize

## Returns
  * Map with configuration summary

## Examples

    iex> config = Exdantic.Config.create(strict: true, extra: :forbid)
    iex> Exdantic.Config.summary(config)
    %{
      validation_mode: "strict",
      extra_fields: "forbidden",
      coercion: "safe",
      frozen: false,
      features: ["validate_assignment", ...]
    }

# `to_json_schema_opts`

```elixir
@spec to_json_schema_opts(t()) :: keyword()
```

Converts configuration to options suitable for JSON Schema generation.

## Parameters
  * `config` - The configuration to convert

## Returns
  * Keyword list of JSON Schema options

## Examples

    iex> config = Exdantic.Config.create(strict: true, use_enum_values: true)
    iex> Exdantic.Config.to_json_schema_opts(config)
    [strict: true, use_enum_values: true, max_anyof_union_len: 5, ...]

# `to_validation_opts`

```elixir
@spec to_validation_opts(t()) :: keyword()
```

Converts configuration to options suitable for validation functions.

## Parameters
  * `config` - The configuration to convert

## Returns
  * Keyword list of validation options

## Examples

    iex> config = Exdantic.Config.create(strict: true, coercion: :safe)
    iex> Exdantic.Config.to_validation_opts(config)
    [strict: true, coerce: true, error_format: :detailed, ...]

# `validate_config`

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

Validates configuration options for consistency.

## Parameters
  * `config` - The configuration to validate

## Returns
  * `:ok` if configuration is valid
  * `{:error, reasons}` if configuration has issues

## Examples

    iex> config = Exdantic.Config.create(strict: true, extra: :allow)
    iex> Exdantic.Config.validate_config(config)
    {:error, ["strict mode conflicts with extra: :allow"]}

    iex> config = Exdantic.Config.create(strict: true, extra: :forbid)
    iex> Exdantic.Config.validate_config(config)
    :ok

---

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