"""Unit tests for AgentProfile Pydantic model."""

from navi.profiles.base import AgentProfile


class TestModelCoercion:
    def test_model_string_to_list(self):
        p = AgentProfile(
            id="test",
            name="Test",
            description="desc",
            system_prompt="sys",
            enabled_tools=[],
            model="gemma4:31b-cloud",
        )
        assert p.model == ["gemma4:31b-cloud"]

    def test_model_list_passthrough(self):
        p = AgentProfile(
            id="test",
            name="Test",
            description="desc",
            system_prompt="sys",
            enabled_tools=[],
            model=["a", "b"],
        )
        assert p.model == ["a", "b"]

    def test_empty_model_defaults(self):
        p = AgentProfile(
            id="test",
            name="Test",
            description="desc",
            system_prompt="sys",
            enabled_tools=[],
            model="",
        )
        assert p.model == ["gemma4:31b-cloud"]


class TestDefaults:
    def test_default_flags(self):
        p = AgentProfile(
            id="test",
            name="Test",
            description="desc",
            system_prompt="sys",
            enabled_tools=[],
        )
        assert p.think_enabled is True
        assert p.planning_enabled is False
        assert p.planning_phase2_enabled is False
        assert p.iteration_budget_enabled is True
        assert p.anti_stall_enabled is True
        assert p.anti_stall_threshold == 8
        assert p.subagent_think_enabled is None
        assert p.final_intercept_enabled is True
        assert p.final_intercept_limit == 2

    def test_max_iterations_default(self):
        p = AgentProfile(
            id="test",
            name="Test",
            description="desc",
            system_prompt="sys",
            enabled_tools=[],
        )
        assert p.max_iterations == 10


class TestExtraFields:
    def test_extra_fields_allowed(self):
        p = AgentProfile(
            id="test",
            name="Test",
            description="desc",
            system_prompt="sys",
            enabled_tools=[],
            custom_field="whatever",
        )
        assert p.model_dump()["custom_field"] == "whatever"


class TestAutonomyFlags:
    def test_new_flags_default_off(self):
        p = AgentProfile(
            id="test",
            name="Test",
            description="desc",
            system_prompt="sys",
            enabled_tools=[],
        )
        assert p.scope_boundary_enabled is False
        assert p.observe_skips_plan_enabled is False
