import pytest
from httpx import AsyncClient

@pytest.mark.asyncio
async def test_explain_not_found(async_client: AsyncClient):
    """Test that non-existent ID returns 404"""
    # Since we're in dev mode with auth overrides, no auth headers needed
    r = await async_client.get("/api/v2/match/explain/does-not-exist")
    assert r.status_code == 404

@pytest.mark.asyncio
async def test_explain_not_found_with_kind(async_client: AsyncClient):
    """Test that explain with kind param returns 404 for non-existent ID"""
    r = await async_client.get("/api/v2/match/explain/does-not-exist?kind=l2a")
    assert r.status_code == 404

@pytest.mark.asyncio  
async def test_explain_with_mock_data(async_client: AsyncClient):
    """Test explain endpoint structure (would need DB fixture for real test)"""
    # This test checks the endpoint exists and returns 404 for non-existent data
    r = await async_client.get("/api/v2/match/explain/test-id-123")
    assert r.status_code == 404
    assert "not found" in r.json()["detail"].lower()

@pytest.mark.asyncio
async def test_dedupe_suggestions_structure(async_client: AsyncClient):
    """Test dedupe suggestions endpoint structure"""
    # Test without response model validation first
    r = await async_client.get(
        "/api/v2/dedupe/suggestions?object_type=Account&page=1&page_size=5"
    )
    # Should return 200 even with empty results in dev mode
    assert r.status_code == 200
    data = r.json()
    assert "items" in data
    assert "page" in data
    assert "total" in data
    assert "page_size" in data
    
    # If there are items, validate the structure
    if data["items"]:
        item = data["items"][0]
        # Check for key fields that should always be present
        assert "id" in item
        assert "object_type" in item
        assert "score" in item or item.get("score") == 0