"""Non-empty output validation for pulumi-vsphere stack results."""

from __future__ import annotations

from typing import Any


def _is_empty(value: Any) -> bool:
    if value is None:
        return True
    if isinstance(value, str) and not value.strip():
        return True
    if isinstance(value, (list, dict, tuple, set)) and len(value) == 0:
        return True
    return False


def assert_nonempty(outputs: dict[str, Any], *, required: list[str] | None = None) -> list[str]:
    """Return list of error messages for empty/missing outputs."""

    errors: list[str] = []
    keys = required if required is not None else list(outputs)
    if not keys:
        errors.append("no outputs exported")
        return errors
    for key in keys:
        if key not in outputs:
            errors.append(f"missing output: {key}")
            continue
        if _is_empty(outputs[key]):
            errors.append(f"empty output: {key}={outputs[key]!r}")
    return errors
