"""Hypothesis strategies for config round-trip property tests (TS-13).

Co-located with the config tests so multiple property tests share one set of
strategies (TS-13: "strategies live next to the round-trip code in a
`_strategies.py` module"). Test-side, not in `src/`, so the runtime package
never imports hypothesis.
"""

from __future__ import annotations

from hypothesis import strategies as st

from mgf.common.settings import LoggingSettings, MgfSettings


def logging_settings() -> st.SearchStrategy[LoggingSettings]:
    """A `LoggingSettings` with varied, valid, round-trippable fields."""
    return st.builds(
        LoggingSettings,
        level=st.sampled_from(["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]),
        format=st.sampled_from(["text", "json", "auto"]),
        journald=st.booleans(),
        rotating_max_bytes=st.integers(min_value=1024, max_value=10**8),
        rotating_backup_count=st.integers(min_value=0, max_value=50),
    )


def mgf_settings() -> st.SearchStrategy[MgfSettings]:
    """An `MgfSettings` with generated logging config.

    Uses ``preset="explicit"`` so the load-time preset does NOT re-derive
    the logging fields — the generated values survive the round-trip, making
    the property test exercise real variation rather than a preset fixed point.
    """
    return logging_settings().map(
        lambda lg: MgfSettings.testing().model_copy(update={"preset": "explicit", "logging": lg})
    )
