"""Base judge — subclass and implement ``evaluate()`` to create a custom judge."""

from __future__ import annotations

import asyncio
import logging
from abc import ABC, abstractmethod

from evalkit.models import JudgeResponse

logger = logging.getLogger(__name__)


class BaseJudge(ABC):
    """Abstract base class for all judges.

    Subclass this, implement :meth:`evaluate`, and :meth:`evaluate_async`
    is provided for free via ``run_in_executor``.
    """

    @abstractmethod
    def evaluate(self, prompt: str) -> JudgeResponse: ...

    async def evaluate_async(self, prompt: str) -> JudgeResponse:
        logger.debug("Running evaluate_async via executor for %s", type(self).__name__)
        loop = asyncio.get_running_loop()
        return await loop.run_in_executor(None, self.evaluate, prompt)
