"""Agent to describe a board (auto-label its workspace)."""

import logging

from agents import ModelSettings, RunResult
from pydantic import BaseModel

from topix.agents.base import BaseAgent
from topix.agents.datatypes.context import Context
from topix.agents.datatypes.model_enum import ModelEnum

logger = logging.getLogger(__name__)


class BoardDescription(BaseModel):
    """Model to represent the board description."""

    title: str


class DescribeBoard(BaseAgent):
    """Agent to label a board based on its first conversation."""

    def __init__(
        self,
        model: str = ModelEnum.OpenAI.GPT_5_4_NANO,
        instructions_template: str = "describe_board.jinja",
        model_settings: ModelSettings | None = None,
    ):
        """Init method."""
        name = "Describe Board"
        instructions = self._render_prompt(instructions_template)

        if model_settings is None:
            model_settings = ModelSettings(temperature=0.5)

        super().__init__(
            name=name,
            model=model,
            model_settings=model_settings,
            output_type=BoardDescription,
            instructions=instructions,
        )

    async def _output_extractor(
        self, context: Context, output: RunResult
    ) -> str | None:
        return output.final_output.title if output.final_output else None
