"""Answer relevancy metric — does the answer address the question?"""

from __future__ import annotations

from evalkit.metrics.base import BaseMetric
from evalkit.models import TestCase
from evalkit.prompts.answer_relevancy import TEMPLATE


class AnswerRelevancyMetric(BaseMetric):
    """Measures whether the answer directly and completely addresses the question.

    A score of 1.0 means the answer is fully relevant and on-topic.
    A score of 0.0 means the answer is off-topic or irrelevant to the question.
    Context is intentionally excluded from this evaluation — only the question
    and the answer are considered.
    """

    name: str = "answer_relevancy"

    def __init__(self, threshold: float = 0.5) -> None:
        self.threshold = threshold

    def _build_prompt(self, test_case: TestCase) -> str:
        return TEMPLATE.format(
            question=test_case.question,
            answer=test_case.answer,
        )
