"""Stub evaluator for testing without real models."""

import random
import hashlib
from typing import Dict, Any

from .base import BaseEvaluator


class StubEvaluator(BaseEvaluator):
    """Stub evaluator that returns fake decisions for testing."""
    
    def evaluate(self, item: Dict[str, Any]) -> Dict[str, Any]:
        """Return deterministic fake decision based on content hash."""
        content = item.get("content", "")
        content_hash = hashlib.sha256(content.encode()).hexdigest()[:8]
        
        # Use hash to seed deterministic randomness
        seed = int(content_hash, 16)
        rng = random.Random(seed)
        
        decisions = {}
        for model_cfg in self.config.models:
            model_id = f"{model_cfg.provider}/{model_cfg.model}"
            decisions[model_id] = {
                "decision": rng.choice([True, False]),
                "confidence": rng.uniform(0.5, 0.95),
                "latency_ms": rng.uniform(10, 100),
            }
        
        # Compute consensus
        decision_values = [d["decision"] for d in decisions.values()]
        consensus = sum(decision_values) > len(decision_values) / 2
        agreement = sum(1 for d in decision_values if d == consensus) / len(decision_values)
        
        return {
            "item_id": item.get("id", "unknown"),
            "content_hash": content_hash,
            "category": item.get("category", "unknown"),
            "decisions": decisions,
            "consensus": consensus,
            "agreement": agreement,
        }
