# bot/telegram_bot.py

from telegram.ext import Application, CommandHandler, MessageHandler, filters
from handlers import command_handlers, message_handlers

import os

def create_bot():
    telegram_token = os.getenv("TELEGRAM_TOKEN")

    application = Application.builder().token(telegram_token).build()

    # ✅ 명령어 핸들러 등록
    application.add_handler(CommandHandler("start", command_handlers.start))

    application.add_handler(CommandHandler("motie_search", command_handlers.motie_search))
    application.add_handler(CommandHandler("motie_map", command_handlers.motie_map))
    application.add_handler(CommandHandler("motie_subscribe", command_handlers.motie_subscribe))
    application.add_handler(CommandHandler("motie_unsubscribe", command_handlers.motie_unsubscribe))

    application.add_handler(CommandHandler("moef_search", command_handlers.moef_search))
    application.add_handler(CommandHandler("moef_map", command_handlers.moef_map))
    application.add_handler(CommandHandler("moef_subscribe", command_handlers.moef_subscribe))
    application.add_handler(CommandHandler("moef_unsubscribe", command_handlers.moef_unsubscribe))

    application.add_handler(CommandHandler("kepco_subscribe", command_handlers.kepco_subscribe))
    application.add_handler(CommandHandler("kepco_unsubscribe", command_handlers.kepco_unsubscribe))

    # 💬 일반 메시지 처리 핸들러
    application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, message_handlers.handle_message))

    application.add_handler(CommandHandler("motie_check", command_handlers.motie_check))
    application.add_handler(CommandHandler("motie_update", command_handlers.motie_update))


    return application
