from __future__ import annotations

import logging
from dataclasses import dataclass

from griptape_nodes.retained_mode.managers.fitness_problems.workflows.workflow_problem import WorkflowProblem

logger = logging.getLogger(__name__)


@dataclass
class MissingTomlSectionProblem(WorkflowProblem):
    """Problem indicating required TOML section is missing from workflow metadata.

    This is one-time only - should only occur once per workflow.
    """

    section_path: str

    @classmethod
    def collate_problems_for_display(cls, instances: list[MissingTomlSectionProblem]) -> str:
        """Display missing TOML section problem."""
        if len(instances) > 1:
            logger.error(
                "MissingTomlSectionProblem received %d instances but should only receive 1. This indicates a logic error.",
                len(instances),
            )

        problem = instances[0]
        return f"'{problem.section_path}' in TOML metadata not found."
