"""Deterministic property contracts for configuration serialization."""

from __future__ import annotations

from hypothesis import given, seed, settings, strategies as st

from obliteratus.config import StudyConfig


PROPERTY_SETTINGS = settings(max_examples=60, deadline=None, database=None)


@seed(7007)
@PROPERTY_SETTINGS
@given(
    batch_size=st.integers(1, 32),
    max_length=st.integers(2, 4096),
    strategy_names=st.lists(
        st.text(alphabet="abcdefghijklmnopqrstuvwxyz_", min_size=1, max_size=16),
        min_size=1,
        max_size=8,
    ),
)
def test_study_config_public_roundtrip_preserves_explicit_values(
    batch_size, max_length, strategy_names,
):
    raw = {
        "model": {"name": "fixture", "device": "cpu"},
        "dataset": {"name": "fixture", "max_samples": 12},
        "strategies": [{"name": name, "params": {"strength": 0.5}} for name in strategy_names],
        "metrics": ["perplexity", "accuracy"],
        "batch_size": batch_size,
        "max_length": max_length,
        "output_dir": "results/property",
    }
    config = StudyConfig.from_dict(raw)
    restored = StudyConfig.from_dict(config.to_dict())
    assert restored == config
