from zscams.agent.src.core.api.backend.client import backend_client
from zscams.agent.src.support.logger import get_logger

logger = get_logger("agent_bootstrap")


def bootstrap():
    """Ensure the agent is bootstrapped with the backend."""

    if backend_client.is_bootstrapped():
        logger.info("Agent ID %s is already bootstrapped.", backend_client.agent_id)
        return

    username = input("LDAP Username: ")
    totp = input("TOTP: ")

    backend_client.login(username, totp)

    equipment_name = input("Equipment Name: ")
    enforced_id = input("Enforced Agent ID (Optional): ")
    backend_client.bootstrap(equipment_name, enforced_id or None)
