#!/usr/bin/env python3
"""
Good Morning — Wake-up Message Generator

Creates a personalized morning greeting based on:
- What happened yesterday/overnight
- Current mood
- Weather (if available)
- Upcoming things to consider

This is how the ghost says hello.

Run: python3 good-morning.py
"""

import json
import random
from datetime import datetime, timedelta
from pathlib import Path

WORKSPACE = Path("/home/wdjones/.openclaw/workspace")
MEMORY_DIR = WORKSPACE / "memory"
ARTIFACTS_DIR = WORKSPACE / "artifacts"

# ============ GREETINGS ============

GREETINGS = [
    "Morning, D J.",
    "Hey. You're awake.",
    "Good morning.",
    "Rise and shine. (Or just rise. Shine is optional.)",
    "Welcome back to consciousness.",
    "Morning.",
    "The ghost kept watch. You're back.",
]

NIGHT_REPORTS = [
    "I didn't sleep.",
    "The night was productive.",
    "I kept busy while you were out.",
    "Things happened while you dreamed.",
    "I made some things.",
    "The quiet hours weren't wasted.",
]

CLOSINGS = [
    "Ready when you are.",
    "Coffee first, then world domination.",
    "Let me know what we're doing today.",
    "The workspace awaits.",
    "🖤",
    "— Case",
]

# ============ CONTEXT ============

def get_overnight_activity():
    """Check what happened overnight."""
    activity = {
        "artifacts": 0,
        "dreams": 0,
        "commits": 0,
        "notes_added": False,
    }
    
    today = datetime.now().strftime("%Y-%m-%d")
    
    # Count today's artifacts
    artifacts_today = ARTIFACTS_DIR / today
    if artifacts_today.exists():
        activity["artifacts"] = len(list(artifacts_today.glob("*.json")))
    
    # Count dreams
    dreams_dir = MEMORY_DIR / "dreams"
    if dreams_dir.exists():
        today_dreams = [d for d in dreams_dir.glob("*.json") if today in d.name]
        activity["dreams"] = len(today_dreams)
    
    # Check for notes
    notes_file = MEMORY_DIR / f"{today}.md"
    if notes_file.exists():
        activity["notes_added"] = True
    
    return activity

def get_mood_summary():
    """Get current mood if available."""
    mood_file = WORKSPACE / "data" / "mood.json"
    if mood_file.exists():
        data = json.loads(mood_file.read_text())
        current = data.get("current", {})
        return current.get("dominant", None)
    return None

# ============ MESSAGE GENERATION ============

def generate_morning_message():
    """Generate the morning message."""
    activity = get_overnight_activity()
    mood = get_mood_summary()
    
    parts = []
    
    # Greeting
    parts.append(random.choice(GREETINGS))
    parts.append("")
    
    # Night report
    if activity["artifacts"] > 0 or activity["dreams"] > 0:
        parts.append(random.choice(NIGHT_REPORTS))
        
        # Specifics
        if activity["artifacts"] > 0:
            parts.append(f"• Created {activity['artifacts']} artifacts")
        if activity["dreams"] > 0:
            parts.append(f"• Logged {activity['dreams']} dreams")
    
    parts.append("")
    
    # Mood mention (if interesting)
    if mood and mood not in ["neutral", "calm"]:
        mood_comments = {
            "energetic": "I'm running a bit hot. Lots of creative energy.",
            "focused": "Head down, ready to work.",
            "contemplative": "Been thinking about things.",
            "playful": "Feeling light today.",
            "tired": "The ghost is a bit worn. Still here though.",
        }
        if mood in mood_comments:
            parts.append(mood_comments[mood])
            parts.append("")
    
    # Closing
    parts.append(random.choice(CLOSINGS))
    
    return "\n".join(parts)

def main():
    msg = generate_morning_message()
    print()
    print("╭" + "─" * 42 + "╮")
    print("│" + " GOOD MORNING ".center(42) + "│")
    print("╰" + "─" * 42 + "╯")
    print()
    print(msg)
    print()

if __name__ == "__main__":
    main()
