"""Schedule post-create server onboarding (sudoers + target path detect)."""

from __future__ import annotations

import logging
from typing import Any

logger = logging.getLogger("nexus.server_onboarding")


async def schedule_server_onboarding(
    server_ids: list[int],
    *,
    operator: str,
) -> dict[str, Any] | None:
    """Start background batch job ``onboard`` for *server_ids*; returns job dict or None."""
    ids = [int(x) for x in server_ids if x]
    if not ids:
        return None
    from server.application.services.server_batch_service import start_batch_job

    try:
        return await start_batch_job(
            op="onboard",
            server_ids=ids,
            operator=operator or "admin",
        )
    except Exception as exc:
        logger.warning("schedule_server_onboarding failed ids=%s: %s", ids, exc)
        return None
