"""Quote library for caffeinate-me — 50+ quotes organized by category and mood."""

import random
from datetime import datetime
from typing import Dict, List, Optional

# ---------------------------------------------------------------------------
# Quote categories
# ---------------------------------------------------------------------------

MOTIVATIONAL: List[str] = [
    "Life happens, coffee helps.",
    "All you need is love... and more coffee.",
    "Coffee: the most important meal of the day.",
    "Behind every successful person is a substantial amount of coffee.",
    "First, I drink the coffee. Then I do the things.",
    "You can't buy happiness, but you can buy coffee, and that's pretty close.",
    "Adventure in life is good; consistency in coffee even better.",
    "May your coffee be strong and your Monday be short.",
    "Coffee is the answer. What's the question?",
    "A morning without coffee is like sleep.",
    "Keep calm and drink coffee.",
    "Coffee is always a good idea.",
    "Sometimes I go hours without drinking coffee. It's called sleeping.",
    "Coffee: because adulting is hard.",
    "Rise and grind.",
    "Every day is a second chance — especially after the first coffee.",
    "Brew your own destiny.",
    "Coffee: turning 'I can't' into 'I can, but first let me finish this cup.'",
    "Work hard, drink coffee, be kind.",
    "The secret ingredient is always a little more coffee.",
]

SARCASTIC: List[str] = [
    "I run on caffeine and inappropriate thoughts.",
    "I like my coffee how I like myself: strong, dark, and too hot for you.",
    "Caffeine isn't a drug, it's a vitamin.",
    "I don't need an inspirational quote, I need coffee.",
    "A yawn is a silent scream for coffee.",
    "I'm not a morning person. I'm a coffee person.",
    "Decaf? That's just brown hot water.",
    "Coffee — you can sleep when you're dead.",
    "Save water. Drink coffee.",
    "Espresso yourself.",
    "I would rather suffer through bad coffee than no coffee at all.",
    "Death before decaf.",
    "Coffee: because Monday is going to happen whether you like it or not.",
    "I was normal... then I ran out of coffee.",
    "Not everyone can handle this much coffee. Luckily, I can.",
    "I haven't had my coffee yet. Please lower your expectations.",
    "My blood type is coffee.",
    "Coffee: the legal way to feel superhuman.",
    "I don't have a problem with coffee. I have a problem without it.",
    "Sleep is just a coffee deficiency.",
]

PROGRAMMER: List[str] = [
    "// TODO: Get more coffee",
    "git commit -m 'needs more coffee'",
    "Debug your code, not your caffeine levels.",
    "Code is like coffee: it works better when it's hot.",
    "Ctrl+C, Ctrl+V, Ctrl+Coffee.",
    "Error 404: Coffee not found.",
    "Stack Overflow helped me debug my code. Coffee helped me debug my life.",
    "There are 10 types of developers: those who drink coffee and those who are wrong.",
    "Coffee.exe has stopped working. Please insert more beans.",
    "sudo make me a coffee.",
    "while(!caffeinated) { sleep(); }",
    "I'm not a bug, I'm an undocumented feature who needs coffee.",
    "Compiling... please wait. Also, please get more coffee.",
    "Coffee is my rubber duck.",
    "The best way to fix a bug is with a fresh cup of coffee and fresh eyes.",
    "Error 418: I'm a teapot. Please use the coffee maker.",
    "Coffee: the original hot reload.",
    "It's not a bug, it's a caffeine deficiency.",
    "My code has no bugs... it has unexpected caffeine-related features.",
    "Documentation? I only read bean labels.",
]

WHOLESOME: List[str] = [
    "The smell of fresh coffee in the morning is a hug for your soul.",
    "Good coffee, good morning, good day.",
    "Coffee brings people together.",
    "There's something magical about sharing a cup of coffee with someone you love.",
    "Coffee is a warm hug in a mug.",
    "Every cup of coffee is a reminder that good things take time.",
    "Coffee: where every sip is a moment of joy.",
    "Sharing a pot of coffee is the most intimate thing you can do.",
    "Coffee tastes better when you drink it with a friend.",
    "Life is too short for bad coffee.",
    "Be the reason someone smiles today. Or at least hand them a coffee.",
    "Coffee is proof that good things come to those who wait... three minutes.",
    "A cup of coffee shared with a friend is happiness tasted and time well spent.",
    "The world is a better place when everyone has had their morning coffee.",
    "Coffee: the warm, caffeinated bridge between strangers.",
]

DARK_HUMOR: List[str] = [
    "Coffee: the only thing keeping me from becoming a morning criminal.",
    "I drink coffee to feel like a functioning adult. It's not working.",
    "Coffee: the socially acceptable way to be awake and still hate everything.",
    "I love you more than coffee, but please don't make me prove it.",
    "Coffee is just bean soup and you can't convince me otherwise.",
    "Coffee: because therapy is expensive.",
    "I'm not addicted to coffee. We're just in a committed relationship.",
    "My doctor said I drink too much coffee. I fired my doctor.",
    "I've replaced my emotional support animal with an espresso machine.",
    "Coffee doesn't ask silly questions. Coffee understands.",
]

MORNING: List[str] = [
    "Good morning! The coffee machine is the real alarm clock.",
    "Rise, grind, and caffeinate.",
    "Morning has broken... now fix it with coffee.",
    "The first sip of morning coffee is basically meditation.",
    "Sunrise + coffee = possibility.",
    "Another beautiful morning ruined by waking up. Coffee to the rescue!",
    "Morning coffee: because you deserve better than being a zombie.",
    "The early bird gets the coffee.",
    "Start your day with a grateful heart and a strong cup of coffee.",
    "Before anything else, morning coffee.",
]

AFTERNOON: List[str] = [
    "3 PM hits different with an iced coffee.",
    "The afternoon slump is no match for a strong cup.",
    "Second wind? More like second coffee.",
    "Powering through the afternoon, one sip at a time.",
    "The 2 PM wall is just a lack of coffee.",
    "Halfway through the day — time to refuel.",
    "Afternoon coffee: the reset button for your day.",
    "When in doubt, coffee it out.",
    "The afternoon belongs to those who keep brewing.",
    "Keep calm and have an afternoon coffee.",
]

EVENING: List[str] = [
    "The decaf debate: live dangerously or sleep tonight?",
    "One more cup won't hurt... much.",
    "Evening coffee: for the brave, the strong, and the deadline-driven.",
    "Coffee: because the night shift doesn't care about your sleep schedule.",
    "Late night coffee — because some code just refuses to debug itself.",
    "Night owl fuel: engaged.",
    "You're not tired, you just need more coffee.",
    "The stars and the coffee drinkers come out at night.",
    "Moonlight and espresso — a dangerous combination.",
    "Real developers ship at midnight. Coffee makes it possible.",
]

# ---------------------------------------------------------------------------
# Mood and time-of-day mappings
# ---------------------------------------------------------------------------

MOOD_CATEGORIES: Dict[str, List[List[str]]] = {
    "energetic": [MOTIVATIONAL, PROGRAMMER],
    "sleepy":    [DARK_HUMOR, SARCASTIC],
    "stressed":  [SARCASTIC, PROGRAMMER, DARK_HUMOR],
    "zen":       [WHOLESOME, MORNING],
}

TIME_CATEGORIES: Dict[str, List[List[str]]] = {
    "morning":   [MORNING, MOTIVATIONAL],
    "midday":    [MOTIVATIONAL, PROGRAMMER],
    "afternoon": [AFTERNOON, PROGRAMMER],
    "evening":   [EVENING, DARK_HUMOR],
}

_ALL_CATEGORIES: List[List[str]] = [
    MOTIVATIONAL, SARCASTIC, PROGRAMMER, WHOLESOME,
    DARK_HUMOR, MORNING, AFTERNOON, EVENING,
]


def _get_time_period() -> str:
    """Return the current time period label."""
    hour = datetime.now().hour
    if 5 <= hour < 11:
        return "morning"
    elif 11 <= hour < 14:
        return "midday"
    elif 14 <= hour < 20:
        return "afternoon"
    return "evening"


def get_random_quote(mood: Optional[str] = None) -> str:
    """
    Get a random coffee quote.

    Args:
        mood: Optional mood filter ('energetic', 'sleepy', 'stressed', 'zen').
              Falls back to time-of-day selection when not provided or unrecognised.

    Returns:
        A random coffee quote string.
    """
    if mood and mood in MOOD_CATEGORIES:
        pool = random.choice(MOOD_CATEGORIES[mood])
    else:
        time_period = _get_time_period()
        pool = random.choice(TIME_CATEGORIES[time_period])
    return random.choice(pool)


def get_all_quotes() -> List[str]:
    """Return every quote from all categories (flattened, preserving duplicates)."""
    all_quotes: List[str] = []
    for category in _ALL_CATEGORIES:
        all_quotes.extend(category)
    return all_quotes


def get_quotes_by_category(category: str) -> List[str]:
    """Get quotes for a named category. Returns an empty list for unknown names."""
    mapping: Dict[str, List[str]] = {
        "motivational": MOTIVATIONAL,
        "sarcastic":    SARCASTIC,
        "programmer":   PROGRAMMER,
        "wholesome":    WHOLESOME,
        "dark_humor":   DARK_HUMOR,
        "morning":      MORNING,
        "afternoon":    AFTERNOON,
        "evening":      EVENING,
    }
    return mapping.get(category, [])
