import logging

from aiogram import Dispatcher

from app.data.commands import ALL_COMMANDS_LISTS, USING_SCOPES
from app.misc.colorize import yellow


async def setup_commands(dp: Dispatcher):
    """
    Установка списков команд.
    Предварительно производится удаление старых списков для корректного отображения.
    """
    for scope in USING_SCOPES:
        result = await dp.bot.delete_my_commands(scope)
        if not result:
            logging.critical(f"Can't delete commands on scope: {scope}")
            raise SystemExit(1)
    logging.info(yellow("Commands are successfully deleted"))

    for commands in ALL_COMMANDS_LISTS:
        await dp.bot.set_my_commands(commands.commands, commands.scope)
    logging.info(yellow('Setup bot commands'))
