from __future__ import annotations

from typing import List, override

from tqdm import tqdm

from srs2std.evaluate.factcheck_strategies.scorers.scorer import Scorer
from srs2std.evaluate.factcheck_strategies.strategy import (
    Conclusion,
    FactcheckStrategy,
    Verdict,
)


class Thresholding(FactcheckStrategy):
    def __init__(self, threshold: float, scorer: Scorer):
        self.threshold = threshold
        self.scorer = scorer

    @override
    def run(self, doc: str, claims: List[str]) -> List[Verdict]:
        predictions = []
        for claim in tqdm(claims):
            candidate = self.scorer.score(doc, claim)
            conclusion = (
                Conclusion.SUPPORTED
                if candidate.score > self.threshold
                else Conclusion.UNSUPPORTED
            )
            prediction = Verdict(conclusion=conclusion, claim=claim, evidence=candidate)
            predictions.append(prediction)
        return predictions
