"""
ConfigSettings from a nested TOML table (not the file root).

Set ``toml_table_header`` to the dot path of the table (e.g. ``"worker"`` or
``"services.api"``). Pi-conf loads the file, then slices that subtree before
building the Pydantic model, so your fields match only that section.

This uses ``sample_layered_config.toml``, which also contains app-level keys;
those are ignored when loading ``WorkerSettings`` because only the ``[worker]``
slice is passed to Pydantic.

Install: pip install 'pi-conf[pydantic]' (or your package manager equivalent).
"""

from __future__ import annotations

import sys
from pathlib import Path

_ROOT = Path(__file__).resolve().parents[1]
if str(_ROOT) not in sys.path:
    sys.path.insert(0, str(_ROOT))

from pi_conf.config_settings import ConfigDict, ConfigSettings


class WorkerSettings(ConfigSettings):
    """Settings that live under ``[worker]`` in sample_layered_config.toml."""

    queue_name: str
    concurrency: int

    model_config = ConfigDict(toml_table_header="worker")


def main() -> None:
    path = Path(__file__).resolve().parent / "sample_layered_config.toml"
    settings = WorkerSettings(config_file=path)

    print("ConfigSettings scoped to [worker] (toml_table_header)")
    print(f"  queue_name: {settings.queue_name!r}")
    print(f"  concurrency: {settings.concurrency}")


if __name__ == "__main__":
    main()
