#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Главный модуль запуска телеграм-бота для управления Synology NAS
"""

import os
import logging
from telegram.ext import (
    Application,
    CommandHandler,
    CallbackQueryHandler,
    MessageHandler,
    filters
)

from src.config.config import TELEGRAM_TOKEN
from src.handlers.command_handlers import (
    start_command,
    help_command,
    status_command,
    power_command,
    power_callback
)
from src.handlers.extended_handlers import (
    storage_command,
    shares_command,
    system_command,
    load_command,
    security_command
)
from src.utils.logger import setup_logging

def main() -> None:
    """Основная функция запуска бота"""
    # Настройка логирования
    setup_logging()
    logger = logging.getLogger(__name__)
    
    # Проверка наличия токена
    if not TELEGRAM_TOKEN:
        logger.error("Telegram token is not set! Please configure TELEGRAM_TOKEN in .env file.")
        return
    
    # Создание и настройка приложения бота
    logger.info("Starting Synology Power Control Bot")
    application = Application.builder().token(TELEGRAM_TOKEN).build()
    
    # Регистрация обработчиков команд
    application.add_handler(CommandHandler("start", start_command))
    application.add_handler(CommandHandler("help", help_command))
    application.add_handler(CommandHandler("status", status_command))
    application.add_handler(CommandHandler("power", power_command))
    
    # Регистрация обработчика callback-запросов
    application.add_handler(CallbackQueryHandler(power_callback))
    
    # Запуск бота
    logger.info("Bot started. Press Ctrl+C to stop.")
    application.run_polling(allowed_updates=Application.ALL_UPDATES)
    
if __name__ == "__main__":
    main()
