"""Non-UI helpers for onboarding state detection."""

from __future__ import annotations

from pathlib import Path

import yaml

CONFIG_PATH = Path("~/.ambient/config.yaml").expanduser()


def needs_onboarding(config_path: Path | None = None) -> bool:
    """True if the local worker config is missing or incomplete."""
    config_path = config_path or CONFIG_PATH
    if not config_path.exists():
        return True
    try:
        with config_path.open(encoding="utf-8") as fh:
            data = yaml.safe_load(fh) or {}
        return not data.get("coordinator_url") or not data.get("worker_id")
    except Exception:
        return True
