"""
ChunkHive Aggregator Scorer
===========================

Combines multiple scoring strategies into a final score.

Supports:
- Modular scorers
- Weighted scoring
- Detailed explainability
- Easy extensibility
"""

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


class AggregatorScorer:
    """
    Aggregates multiple scorers into a single unified score.
    """

    def __init__(self, scorers: List[BaseScorer]):
        self.scorers = scorers

    def score(self, query: str, chunk: Any) -> ScoreResult:
        total_score = 0.0
        combined_details: Dict[str, Any] = {}
        scorer_breakdown: Dict[str, float] = {}

        for scorer in self.scorers:
            result = scorer.score(query, chunk)

            total_score += result.score
            scorer_name = scorer.__class__.__name__

            scorer_breakdown[scorer_name] = result.score

            combined_details[scorer_name] = result.details

        return ScoreResult(
            score=total_score,
            details={
                "total_score": total_score,
                "breakdown": scorer_breakdown,
                "components": combined_details,
            },
        )
