"""Pytest configuration and shared fixtures for ship-crewai tests."""

import pytest


@pytest.fixture
def mock_score_response():
    """Mock SHIP API score response."""
    return {
        "score": 85,
        "grade": "A",
        "breakdown": {
            "confidence": 88,
            "focus": 82,
            "context": 85,
            "efficiency": 84,
        },
        "repo": "owner/repo",
        "commits_analyzed": 150,
        "ai_commit_ratio": 0.42,
    }


@pytest.fixture
def mock_detect_response():
    """Mock SHIP API detect response."""
    return {
        "ai_probability": 0.87,
        "is_ai_generated": True,
        "confidence": 0.92,
        "features_analyzed": 174,
        "model_version": "v2-174feat",
        "top_signals": [
            {"feature": "ast_depth_mean", "weight": 0.15},
            {"feature": "docstring_ratio", "weight": 0.12},
            {"feature": "variable_name_length_mean", "weight": 0.09},
        ],
    }


@pytest.fixture
def mock_health_response():
    """Mock SHIP API health response."""
    return {
        "status": "ok",
        "version": "2.0.0",
        "uptime_seconds": 86400,
        "endpoints": {
            "score": "operational",
            "detect": "operational",
        },
    }


@pytest.fixture
def sample_python_code():
    """Sample Python code for detection tests."""
    return '''def calculate_total(items: list[dict]) -> float:
    """Calculate the total price of all items.

    Args:
        items: List of item dicts with 'price' and 'quantity' keys.

    Returns:
        Total price as a float.
    """
    total = 0.0
    for item in items:
        price = item.get("price", 0)
        quantity = item.get("quantity", 1)
        total += price * quantity
    return total
'''


@pytest.fixture
def sample_typescript_code():
    """Sample TypeScript code for detection tests."""
    return '''export function calculateTotal(items: Item[]): number {
  return items.reduce((total, item) => {
    return total + (item.price * item.quantity);
  }, 0);
}
'''
