import pytest
from unittest.mock import MagicMock, patch
from pydantic import BaseModel
from armorer.agent import BaseAgent as ArmorerAgent
from armorer.installers.schemas import DeploymentPlan, ExecutionResult

class MockModel(BaseModel):
    test_field: str

def test_agent_structured_output_model():
    """Verify that ArmorerAgent.run returns a Pydantic object when structured_output_model is provided."""
    agent = ArmorerAgent()
    mock_agent = MagicMock()
    mock_result = MagicMock()
    mock_result.structured_output = MockModel(test_field="success")
    mock_agent.return_value = mock_result
    
    with patch.object(agent, "_persistent_agent", mock_agent):
        res = agent.run("test", structured_output_model=MockModel)
        assert isinstance(res, MockModel)
        assert res.test_field == "success"
        mock_agent.assert_called_once_with("test", structured_output_model=MockModel)

def test_deployment_plan_model():
    """Verify DeploymentPlan Pydantic model validation."""
    data = {
        "docker_compose": "version: '3'\nservices:\n  web: image: nginx",
        "intent_checklist": ["Install dependencies", "Start web server"]
    }
    plan = DeploymentPlan(**data)
    assert plan.docker_compose == data["docker_compose"]
    assert len(plan.intent_checklist) == 2
    assert plan.intent_checklist[0] == "Install dependencies"

def test_execution_result_model():
    """Verify ExecutionResult Pydantic model validation."""
    data = {
        "success": True,
        "message": "deployment stable",
        "access_urls": ["http://localhost:8080"]
    }
    res = ExecutionResult(**data)
    assert res.success is True
    assert res.message == "deployment stable"
    assert "http://localhost:8080" in res.access_urls
