"""ND0803: Workflow has no description."""

from pathlib import Path
from typing import Any

from valn8n_lib.rules.registry import SourceMap, register
from valn8n_lib.source_map import lookup_line
from valn8n_lib.types import Diagnostic, RuleCode, Severity, SuggestionLevel

_RULE_CODE = RuleCode("ND0803", Severity.HINT)


@register(
    "ND0803",
    Severity.HINT,
    description="Workflow has no description",
    strict=False,
)
def check_missing_workflow_description(
    workflow: dict[str, Any],
    path: Path,
    source_map: SourceMap = None,
    suggestions: SuggestionLevel = SuggestionLevel.FULL,
) -> list[Diagnostic]:
    """Flag workflows with missing or empty description."""
    description = workflow.get("description", "").strip()
    if description:
        return []

    fname = str(path)
    pointer = "/description"
    line = lookup_line(source_map, pointer)
    return [
        Diagnostic(
            file=fname,
            location=None,
            code=_RULE_CODE,
            message="Workflow has no description; consider adding one to document its purpose",
            line=line,
        ),
    ]
