"""
Entry point — runs Telegram bot and FastAPI admin panel concurrently.
"""
import asyncio
import os
from dotenv import load_dotenv

load_dotenv()


async def run_bot():
    from bot.bot import dp, bot, init_db
    await init_db()
    print("🤖 Bot started")
    await dp.start_polling(bot)


async def run_admin():
    import uvicorn
    port = int(os.getenv("ADMIN_PORT", 8000))
    config = uvicorn.Config(
        "admin.app:app",
        host="0.0.0.0",
        port=port,
        log_level="warning",
    )
    server = uvicorn.Server(config)
    print(f"🌐 Admin panel: http://localhost:{port}")
    await server.serve()


async def main():
    await asyncio.gather(run_bot(), run_admin())


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