"""Contract tests: ARIAPolicyProvider satisfies PolicyProviderInterface.

Imports real AGT types from agent-os-kernel to verify structural
compatibility with the PolicyProviderInterface protocol.
"""

from __future__ import annotations

import httpx
import pytest
from agent_control_plane.interfaces.plugin_interface import (  # type: ignore[import-untyped]
    PolicyProviderInterface,
)

from aria_agentkit.policy.provider import ARIAPolicyProvider


@pytest.fixture
def provider() -> ARIAPolicyProvider:
    def handler(request: httpx.Request) -> httpx.Response:
        return httpx.Response(
            status_code=200,
            json={
                "policies": [
                    {
                        "id": "p1",
                        "name": "test",
                        "description": "d",
                        "rules": [{"action_type": "tool.invoke"}],
                    }
                ]
            },
        )

    return ARIAPolicyProvider(
        pdp_base_url="http://localhost:8001",
        pdp_application="contract-test",
        token="test-token",
        http_client=httpx.Client(transport=httpx.MockTransport(handler)),
    )


@pytest.mark.contract
class TestProviderProtocol:
    def test_is_instance_of_policy_provider_interface(self, provider: ARIAPolicyProvider) -> None:
        assert isinstance(provider, PolicyProviderInterface)

    def test_has_get_policies_method(self, provider: ARIAPolicyProvider) -> None:
        assert hasattr(provider, "get_policies")
        assert callable(provider.get_policies)

    def test_has_refresh_method(self, provider: ARIAPolicyProvider) -> None:
        assert hasattr(provider, "refresh")
        assert callable(provider.refresh)

    def test_has_metadata_property(self, provider: ARIAPolicyProvider) -> None:
        assert hasattr(provider, "metadata")
        meta = provider.metadata
        assert meta.name == "aria-pdp"

    def test_get_policies_returns_list(self, provider: ARIAPolicyProvider) -> None:
        policies = provider.get_policies()
        assert isinstance(policies, list)
        assert len(policies) == 1
        assert policies[0].policy_id == "p1"
