from commands.actions import (
    force_sleep,
    wake_up,
    set_mood,
    reset_mood,
    check_mood,
    calm_miku,
    reset_conversation,
    send_bedtime_now
)
from utils.moods import nickname_mood_emoji
import globals

async def handle_command(message, set_sleep_state):
    text = message.content.lower().strip()

    # !miku sleep
    if text == "!miku sleep":
        # force_sleep is async, pass set_sleep_state
        await force_sleep(set_sleep_state)
        await message.channel.send("Yaaawn... Okay... Goodnight~ 💫")
        return True, globals.CURRENT_MOOD_NAME, globals.CURRENT_MOOD, globals.PREVIOUS_MOOD_NAME, globals.IS_SLEEPING

    # !miku wake
    if text == "!miku wake":
        await wake_up(set_sleep_state)
        await message.channel.send("Rise and shine, good morning! 🌞")
        return True, globals.CURRENT_MOOD_NAME, globals.CURRENT_MOOD, globals.PREVIOUS_MOOD_NAME, globals.IS_SLEEPING

    # !miku mood <mood>
    if text.startswith("!miku mood "):
        new_mood = text.split("!miku mood ")[1].strip()
        if set_mood(new_mood):
            await message.channel.send(f"🌈 Miku's mood has been set to **{new_mood}**!")
        else:
            await message.channel.send("⚠️ I don't recognize that mood. Try again with a valid one.")
        await nickname_mood_emoji()
        return True, globals.CURRENT_MOOD_NAME, globals.CURRENT_MOOD, globals.PREVIOUS_MOOD_NAME, globals.IS_SLEEPING

    # !miku mood-reset
    if text == "!miku mood-reset":
        reset_mood()
        await message.channel.send("🔄 Miku’s mood has been reset to **neutral**.")
        await nickname_mood_emoji()
        return True, globals.CURRENT_MOOD_NAME, globals.CURRENT_MOOD, globals.PREVIOUS_MOOD_NAME, globals.IS_SLEEPING

    # !miku mood-check
    if text == "!miku mood-check":
        current = check_mood()
        await message.channel.send(f"☑️ Miku’s mood is currently {current}.")
        return True, globals.CURRENT_MOOD_NAME, globals.CURRENT_MOOD, globals.PREVIOUS_MOOD_NAME, globals.IS_SLEEPING

    # !miku calm
    if text == "!miku calm":
        calm_miku()
        await message.channel.send("😤➡️😌 Miku has calmed down... for now.")
        return True, globals.CURRENT_MOOD_NAME, globals.CURRENT_MOOD, globals.PREVIOUS_MOOD_NAME, globals.IS_SLEEPING

    # !reset
    if text == "!reset":
        reset_conversation(message.author.id)
        await message.channel.send("Okay! Memory reset for you~ ✨")
        return True, globals.CURRENT_MOOD_NAME, globals.CURRENT_MOOD, globals.PREVIOUS_MOOD_NAME, globals.IS_SLEEPING

    # !miku bedtime
    if text == "!miku bedtime":
        await message.channel.send("🌙 Miku is preparing a bedtime reminder...")
        await send_bedtime_now()
        return True, globals.CURRENT_MOOD_NAME, globals.CURRENT_MOOD, globals.PREVIOUS_MOOD_NAME, globals.IS_SLEEPING

    # fallback
    return False, globals.CURRENT_MOOD_NAME, globals.CURRENT_MOOD, globals.PREVIOUS_MOOD_NAME, globals.IS_SLEEPING
