"""Experimental Telegram bot provisioning helpers.

This module is intentionally isolated behind a feature flag and should never
impact the default, official BotFather token flow.
"""

from __future__ import annotations

from typing import Any


def attempt_bot_creation(config_manager: Any) -> dict[str, str]:
    """Best-effort experimental bot creation attempt.

    Official Telegram Bot API does not support bot creation directly, so this
    path can only work via user-account automation tooling (optional deps and
    credentials). When prerequisites are missing, callers should fall back to
    the normal BotFather/manual token path.
    """

    api_id = str(config_manager.get_key("TELEGRAM_API_ID") or "").strip()
    api_hash = str(config_manager.get_key("TELEGRAM_API_HASH") or "").strip()
    phone = str(config_manager.get_key("TELEGRAM_USER_PHONE") or "").strip()
    if not (api_id and api_hash and phone):
        return {
            "status": "unavailable",
            "reason": (
                "Missing TELEGRAM_API_ID/TELEGRAM_API_HASH/TELEGRAM_USER_PHONE "
                "for user-account automation."
            ),
        }

    try:
        __import__("telethon")
    except Exception:
        return {
            "status": "unavailable",
            "reason": "Telethon is not installed in this runtime.",
        }

    return {
        "status": "failed",
        "reason": (
            "Experimental BotFather automation is not fully implemented in this build. "
            "Falling back to the official token flow."
        ),
    }
