# globals.py
import os
from collections import defaultdict, deque
import discord
from langchain_ollama import OllamaEmbeddings
from apscheduler.schedulers.asyncio import AsyncIOScheduler

scheduler = AsyncIOScheduler()

BEDTIME_CHANNEL_IDS = [761014220707332107]

# Stores last 5 exchanges per user (as deque)
conversation_history = defaultdict(lambda: deque(maxlen=5))

DISCORD_BOT_TOKEN = os.getenv("DISCORD_BOT_TOKEN")
OLLAMA_URL = os.getenv("OLLAMA_URL", "http://ollama:11434")
OLLAMA_MODEL = os.getenv("OLLAMA_MODEL", "llama3.1")

embeddings = OllamaEmbeddings(
    model=OLLAMA_MODEL,
    base_url=OLLAMA_URL
)

# Set up Discord client
intents = discord.Intents.default()
intents.message_content = True
intents.members = True
intents.presences = True
client = discord.Client(intents=intents)

current_model = None  # Track currently loaded model name

KINDNESS_KEYWORDS = [
    "thank you", "love you", "luv u", "you're the best", "so cute",
    "adorable", "amazing", "sweet", "kind", "great job", "well done",
    "precious", "good girl", "cutie", "angel", "my favorite", "so helpful"
]
HEART_REACTIONS = ["💙", "💝", "💖", "💕", "💜", "❤️‍🔥", "☺️"]
kindness_reacted_messages = set()

AUTO_MOOD = True
CURRENT_MOOD = "neutral"
CURRENT_MOOD_NAME = "neutral"
PREVIOUS_MOOD_NAME = "neutral"
IS_SLEEPING = False
AVAILABLE_MOODS = [
    "bubbly", "sleepy", "curious", "shy", "serious", "excited", "silly",
    "melancholy", "flirty", "romantic", "irritated", "angry", "neutral"
]

BOT_USER = None
AUTONOMOUS_CHANNEL_ID = 761014220707332107
TARGET_GUILD_ID = 759889672804630530

SLEEPY_RESPONSES_LEFT = None  # None means not sleeping or no count set
ANGRY_WAKEUP_TIMER = None     # store asyncio.Task for angry cooldown
FORCED_ANGRY_UNTIL = None     # datetime when angry mood expires
JUST_WOKEN_UP = False

LAST_FULL_PROMPT = ""
