import asyncio
import uvicorn

from bot.logging_setup import setup_logging
setup_logging()  # до всех остальных импортов

from database.connection import init_db
from bot.setup import create_bot_and_dispatcher
from admin.app import create_admin_app
import config


async def main() -> None:
    await init_db()

    bot, dp = create_bot_and_dispatcher()
    admin_app = create_admin_app()

    server = uvicorn.Server(
        uvicorn.Config(
            admin_app,
            host=config.ADMIN_HOST,
            port=config.ADMIN_PORT,
            log_level="info",
        )
    )

    await asyncio.gather(
        dp.start_polling(bot, skip_updates=True),
        server.serve(),
    )


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