# app/bot/handlers/start.py
from telebot.types import Message
from telebot import logger
from app.bot.keyboards.main_menu import get_main_menu
from app.bot.constants import UserStates
from app.bot.states import UserStateManager
from app.bot.utils.auth import check_registration


def register_handlers(bot,app, state_manager: UserStateManager):
    @bot.message_handler(commands=['start'])
    @bot.message_handler(func=lambda msg: msg.text == "Продолжить" and state_manager.get_state(msg.chat.id) == UserStates.REGISTRATION)
    def start_handler(message: Message):
        chat_id = message.chat.id
        username = f"{message.from_user.username}" if message.from_user.username else "N/A"
        user = check_registration(bot, message,app)
        if not user:
            state_manager.set_state(chat_id, UserStates.REGISTRATION)
            logger.warning(f"Неавторизованный пользователь {chat_id} @{username}")
            return
        else:
            state_manager.set_state(chat_id, UserStates.MAIN_MENU)
            bot.send_message(chat_id, f"👋 Привет, {username}!", reply_markup=get_main_menu())




