"""
Core types test configuration.

Registers Hypothesis strategies for property-based testing of core types.
"""

from lattice.core.types.enums import Role
from lattice.core.types.log import LogEntry


def _register_hypothesis_strategies() -> None:
    """Register Hypothesis strategies for core types."""
    try:
        from hypothesis import strategies as st
        from hypothesis.strategies import DrawFn

        @st.composite
        def valid_log_entry(draw: DrawFn) -> LogEntry:
            """Generate a valid LogEntry that respects @deal.inv constraints."""
            role = draw(st.sampled_from(Role))

            if role == Role.TOOL:
                # TOOL role: tool_* fields allowed, but not empty strings
                tool_input = draw(st.none() | st.text(min_size=1))
                tool_status = draw(st.none() | st.text(min_size=1))
                tool_error = draw(st.none() | st.text(min_size=1))
            else:
                # Non-TOOL role: tool_* must be None
                tool_input = None
                tool_status = None
                tool_error = None

            return LogEntry(
                external_id=draw(st.text(min_size=0)),
                session_id=draw(
                    st.text(min_size=1)
                ),  # Must be non-empty per _log_entry_is_valid
                timestamp=draw(
                    st.text(min_size=1)
                ),  # Must be non-empty per _log_entry_is_valid
                role=role,
                content=draw(st.text(min_size=0)),
                tool_input=tool_input,
                tool_status=tool_status,
                tool_error=tool_error,
            )

        # Register the strategy for LogEntry
        st.register_type_strategy(LogEntry, valid_log_entry())

    except ImportError:
        # Hypothesis not available, skip registration
        pass


_register_hypothesis_strategies()
