"""
Dependency Scorer
=================

Boosts chunks that are:
- Entry points
- High call-frequency
- Central modules
"""

from typing import Dict, Any
from .base import BaseScorer, ScoreResult


class DependencyScorer(BaseScorer):

    def score(self, query: str, chunk: Any) -> ScoreResult:

        score = 0.0
        details: Dict[str, float] = {}

        metadata = getattr(chunk, "metadata", {})

        # Entry point boost
        if metadata.get("is_entrypoint"):
            score += 1.0
            details["entrypoint_boost"] = 1.0

        # Call frequency boost
        call_count = metadata.get("call_count", 0)
        if call_count > 5:
            boost = min(call_count / 50, 1.0)
            score += boost
            details["call_frequency_boost"] = boost

        weighted = score * self.weight

        return ScoreResult(
            score=weighted,
            details={
                "raw_dependency_score": score,
                "weight": self.weight,
                **details
            }
        )
