import asyncio
import logging
from aiogram import Bot, Dispatcher
from aiogram.types import BotCommand

from config import BOT_TOKEN
from database.models import init_db
from handlers import user, admin

logging.basicConfig(level=logging.INFO)

async def main():
    # ۱. راه اندازی اولیه دیتابیس
    await init_db()

    # ۲. ایجاد نمونه ربات و دیسپچر
    bot = Bot(token=BOT_TOKEN)
    dp = Dispatcher()

    # ۳. ثبت کامندهای منوی تلگرام
    await bot.set_my_commands([
        BotCommand(command="start", description="🔄 شروع مجدد ربات")
    ])

    # ۴. اتصال روترها
    dp.include_router(user.router)
    dp.include_router(admin.router)

    print("🤖 Bot is running with all upgraded features...")

    # ۵. شروع پاشش پیام‌ها (Polling)
    await bot.delete_webhook(drop_pending_updates=True)
    await dp.start_polling(bot)

if __name__ == "__main__":
    asyncio.run(main())