# `PhoenixKit.Settings.Setting`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.87/lib/phoenix_kit/settings/setting.ex#L1)

Setting schema for PhoenixKit system settings.

This schema defines system-wide settings that can be configured through
the admin panel. Settings are stored as key-value pairs with timestamps.

## Fields

- `key`: Setting identifier (unique, required)
- `value`: Setting value (string format, for simple settings)
- `value_json`: Setting value (JSONB format, for complex data structures)
- `module`: Module/feature identifier for organization (optional)
- `date_added`: When the setting was first created
- `date_updated`: When the setting was last modified

## Value Storage Strategy

Settings can use either `value` (string) OR `value_json` (JSONB), but not both:
- Use `value` for simple string settings (themes, toggles, simple config)
- Use `value_json` for complex data (objects, arrays, nested structures)
- When both are present, `value_json` takes precedence

## Default Settings

PhoenixKit includes three default system settings:

- **time_zone**: System timezone offset (default: "0" for UTC)
- **date_format**: Date display format (default: "Y-m-d")
- **time_format**: Time display format (default: "H:i" for 24-hour)

## Usage Examples

    # Create a simple string setting
    %Setting{}
    |> Setting.changeset(%{key: "theme", value: "dark"})
    |> Repo.insert()

    # Create a complex JSON setting
    %Setting{}
    |> Setting.changeset(%{key: "app_config", value_json: %{"theme" => "dark", "features" => ["auth", "admin"]}})
    |> Repo.insert()

    # Update existing setting
    setting
    |> Setting.changeset(%{value: "light"})
    |> Repo.update()

# `changeset`

Creates a changeset for setting creation and updates.

Validates that key and value are present and key is unique.
Automatically sets date_updated to current time on updates.

# `update_changeset`

Creates a changeset for updating only the value field.

This is used when updating existing settings through the admin panel.
Automatically updates the date_updated timestamp.

---

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