import asyncio
import logging

from aiogram import Bot, Dispatcher

from {{ name }}.config import Config, init_config
from {{ name }}.controllers.router import router
{% if has_redis %}
from {{ name }}.db.sql.utils.session import init_session
from {{ name }}.db.redis.redis import init_redis
{% else %}
from {{ name }}.db.utils.session import init_session
{% endif %}
from {{ name }}.middlewares.session import SessionMiddleware
from {{ name }}.middlewares.throttling import ThrottlingMiddleware
from {{ name }}.middlewares.user import UserMiddleware

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)


async def main() -> None:
    init_config()
    init_session()
{% if has_redis %}
    init_redis()
{% endif %}

    bot = Bot(token=Config.c.token)
    dp = Dispatcher()

    dp.message.middleware(ThrottlingMiddleware())
    dp.message.middleware(SessionMiddleware())
    dp.message.middleware(UserMiddleware())
    dp.include_router(router)

    logger.info("Starting bot...")

    if Config.c.updates_strategy == "polling":
        await dp.start_polling(bot)
    else:
        raise ValueError(f"Unknown updates strategy: {Config.c.updates_strategy}")


if __name__ == "__main__":
    asyncio.run(main())
