from handlers.bot_profile_cache import (
    _bot_avatar_file_id,
    _bot_avatar_path,
    _bot_id,
    _bot_identity_lock,
    _bot_username,
    _ensure_bot_identity,
    _get_bot_id,
    get_bot_avatar_file_id,
    get_bot_avatar_thumbnail,
    get_bot_url,
    get_bot_username,  # noqa: F401
)
from handlers.inline_utils import (
    RawAnswerInlineQuery,
    build_inline_album_result,
    build_inline_status_editor,
    build_start_deeplink_url,
    register_inline_send_handlers,
    run_inline_send_callback,
    safe_answer_inline_query,
    sanitize_inline_results,
)
from handlers.logging_utils import (
    build_request_id,
    log_context_scope,
    log_duration,
    with_callback_logging,
    with_chosen_inline_logging,
    with_inline_query_logging,
    with_inline_send_logging,
    with_message_logging,
)
from handlers.telegram_ui_utils import (
    _chat_action_cache,
    _message_edit_cache,
    _send_with_reaction,
    build_progress_status,
    build_queue_busy_text,
    build_queue_status,
    build_rate_limit_text,
    get_message_text,
    handle_download_error,
    handle_download_backpressure_error,
    handle_video_too_large,
    should_skip_duplicate_business_message,
    load_user_settings,
    make_retry_status_notifier,
    make_status_text_progress_updater,
    maybe_delete_user_message,
    react_to_message,
    remove_file,
    resolve_settings_target_id,
    retry_async_operation,
    safe_delete_message,
    safe_edit_inline_media,
    safe_edit_inline_text,
    safe_edit_text,
    send_chat_action_if_needed,
)

def make_backpressure_handler(message, business_id):
    """Build the shared backpressure closure used by the single-media flows:
    forwards DownloadRateLimitError/DownloadQueueBusyError to the user-facing
    handler, showing service status only outside business chats."""

    async def _handle_backpressure(exc: Exception) -> None:
        await handle_download_backpressure_error(
            exc,
            message=message,
            show_service_status=business_id is None,
        )

    return _handle_backpressure


__all__ = [
    "_bot_avatar_file_id",
    "_bot_avatar_path",
    "_bot_id",
    "_bot_identity_lock",
    "_bot_username",
    "_chat_action_cache",
    "_ensure_bot_identity",
    "_get_bot_id",
    "_message_edit_cache",
    "_send_with_reaction",
    "RawAnswerInlineQuery",
    "build_inline_album_result",
    "build_inline_status_editor",
    "build_progress_status",
    "build_queue_busy_text",
    "build_queue_status",
    "build_rate_limit_text",
    "build_request_id",
    "build_start_deeplink_url",
    "get_bot_avatar_file_id",
    "get_bot_avatar_thumbnail",
    "get_bot_url",
    "get_message_text",
    "handle_download_error",
    "handle_download_backpressure_error",
    "handle_video_too_large",
    "should_skip_duplicate_business_message",
    "load_user_settings",
    "log_context_scope",
    "log_duration",
    "make_backpressure_handler",
    "make_retry_status_notifier",
    "make_status_text_progress_updater",
    "maybe_delete_user_message",
    "react_to_message",
    "register_inline_send_handlers",
    "remove_file",
    "resolve_settings_target_id",
    "retry_async_operation",
    "run_inline_send_callback",
    "safe_answer_inline_query",
    "safe_delete_message",
    "safe_edit_inline_media",
    "safe_edit_inline_text",
    "safe_edit_text",
    "sanitize_inline_results",
    "send_chat_action_if_needed",
    "should_skip_duplicate_business_message",
    "with_callback_logging",
    "with_chosen_inline_logging",
    "with_inline_query_logging",
    "with_inline_send_logging",
    "with_message_logging",
]
