from v1.agent.schemas import RunAgentInput


class TestRunAgentInput:
    def test_requires_full_fields(self):
        payload = {
            "threadId": "t1",
            "runId": "r1",
            "state": {},
            "messages": [],
            "tools": [],
            "context": [],
            "forwardedProps": {},
        }
        model = RunAgentInput.model_validate(payload)
        assert model.threadId == "t1"
        assert model.runId == "r1"
        assert model.parentRunId is None
        assert model.state == {}
        assert model.messages == []
        assert model.tools == []
        assert model.context == []
        assert model.forwardedProps == {}
        assert model.resume is None

    def test_resume_optional(self):
        payload = {
            "threadId": "t1",
            "runId": "r2",
            "state": {},
            "messages": [],
            "tools": [],
            "context": [],
            "forwardedProps": {},
            "resume": {"interruptId": "int-1", "payload": {"decision": "approved"}},
        }
        model = RunAgentInput.model_validate(payload)
        assert model.resume is not None
        assert model.resume["interruptId"] == "int-1"
        assert model.resume["payload"]["decision"] == "approved"

    def test_parent_run_id_optional(self):
        payload = {
            "threadId": "t1",
            "runId": "r3",
            "parentRunId": "p1",
            "state": {"key": "value"},
            "messages": [{"role": "user", "content": "hello"}],
            "tools": [{"name": "ui.navigate_to"}],
            "context": [{"type": "user", "id": "u1"}],
            "forwardedProps": {"theme": "dark"},
        }
        model = RunAgentInput.model_validate(payload)
        assert model.parentRunId == "p1"
        assert model.state == {"key": "value"}
        assert len(model.messages) == 1
        assert model.messages[0]["role"] == "user"
