import asyncio
import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

from infrastructure.database.session import get_db_session
from modules.emojis.service import EmojiService


async def main():
    if len(sys.argv) < 3:
        print("Usage: python scripts/sync_emoji_pack.py <PACK_NAME> <BOT_TOKEN> [CATEGORY]")
        print("Example: python scripts/sync_emoji_pack.py AnimatedVIP 123456:ABC-DEF vip")
        sys.exit(1)

    pack_name = sys.argv[1]
    bot_token = sys.argv[2]
    category = sys.argv[3] if len(sys.argv) > 3 else "general"

    print(f"🔄 Syncing pack '{pack_name}' from Telegram Bot API (category: {category})...")
    async with get_db_session() as session:
        service = EmojiService(session)
        result = await service.sync_pack_from_telegram(
            pack_name=pack_name,
            bot_token=bot_token,
            category=category,
        )
        print(f"✅ Success! Synced {result['synced_emojis_count']} custom emojis from '{result['title']}'.")


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