from telegram.ext import (
    Application,
    CommandHandler,
    CallbackQueryHandler,
    MessageHandler,
    filters,
)
from bot.handlers import (
    start,
    handle_button_click,
    manage_hotels,
    hotel_actions,
    delete_hotel,
    check_pms,
    setup_rooms,
    settings_menu,
    toggle_telegram,
    toggle_email,
    show_current_settings,
    statistics,
    generate_statistics,
    stats_select_period,
)

from bot.operations.settings import (
    settings_menu,
    toggle_telegram,
    toggle_email,
    show_current_settings,
    set_notification_time,
    
)

from bot.operations.notifications import (
    handle_notification_time,
)

from bot.operations.users import (
    
    show_users,
 
)

def setup_bot(application: Application):
    """Настройка Telegram бота: регистрация обработчиков."""
    print("Настройка Telegram приложения...")

    # Регистрация обработчиков команд
    application.add_handler(CommandHandler("start", start))

    # Регистрация обработчиков кнопок
    application.add_handler(CallbackQueryHandler(handle_button_click))
    application.add_handler(CallbackQueryHandler(manage_hotels, pattern="^manage_hotels$"))
    application.add_handler(CallbackQueryHandler(show_users, pattern="^manage_users$"))
    application.add_handler(CallbackQueryHandler(settings_menu, pattern="^settings$"))
    application.add_handler(CallbackQueryHandler(toggle_telegram, pattern="^toggle_telegram$"))
    application.add_handler(CallbackQueryHandler(toggle_email, pattern="^toggle_email$"))
    application.add_handler(CallbackQueryHandler(set_notification_time, pattern="^set_notification_time$"))
    application.add_handler(CallbackQueryHandler(show_current_settings, pattern="^current_settings$"))
    application.add_handler(CallbackQueryHandler(hotel_actions, pattern="^hotel_"))
    application.add_handler(CallbackQueryHandler(delete_hotel, pattern="^delete_hotel_"))
    application.add_handler(CallbackQueryHandler(check_pms, pattern="^check_pms_"))
    application.add_handler(CallbackQueryHandler(setup_rooms, pattern="^setup_rooms_"))
    application.add_handler(CallbackQueryHandler(statistics, pattern="^stats$"))
    application.add_handler(CallbackQueryHandler(stats_select_period, pattern="^stats_hotel_"))
    application.add_handler(CallbackQueryHandler(generate_statistics, pattern="^stats_period_"))

    # Регистрация обработчиков текстовых сообщений
    application.add_handler(MessageHandler(filters.TEXT & filters.ChatType.PRIVATE, handle_notification_time))

    print("Обработчики успешно зарегистрированы.")
