"""wivexx_capabilities.py — the single source of truth for everything Wivexx can do.

One canonical catalog powers three things, so they never drift apart:
  • the in-app "capabilities" panel (control room + phone) — discover every command
  • Wivexx's *self-awareness* — a condensed summary is injected into the Claude
    system prompt so it answers accurately when asked about itself
  • the spoken "what can you do?" answer

Keep this list current as features are added — it's the place the assistant looks
to describe itself.
"""
from __future__ import annotations

VERSION = "1.0"   # keep in sync with wivexx_api.WIVEXX_VERSION (shows in the
                  # system prompt + capabilities panel)

# category -> list of {name, desc, say:[examples]}
CATALOG: list[dict] = [
    {"category": "Voice & control", "icon": "🎙", "items": [
        {"name": "Wake / dismiss", "desc": "Say “hey wivexx” to activate; “stand down” / “stop” to return to standby.",
         "say": ["hey wivexx", "stand down"]},
        {"name": "Custom wake words", "desc": "Add your own wake words / pronunciations (e.g. “wybexx”, “wibex”) in shortcuts → wake words; they apply live.",
         "say": []},
        {"name": "Barge-in", "desc": "Talk over Wivexx while it's speaking to interrupt it.", "say": []},
        {"name": "Repeat that", "desc": "Replay the last spoken answer instantly.", "say": ["repeat that"]},
        {"name": "Call mode", "desc": "Wake word off — only listens while you hold push-to-talk (great for calls/games).",
         "say": ["enable call mode", "disable call mode"]},
        {"name": "Type instead of talk", "desc": "Type any command/question in the input bar — same pipeline as voice.", "say": []},
        {"name": "Send images", "desc": "Attach or paste (Ctrl+V) an image and Wivexx analyses it with your text.", "say": []},
    ]},
    {"category": "Apps & environments", "icon": "🧩", "items": [
        {"name": "Open / close apps", "desc": "Launch or close any app you've added in Commands.",
         "say": ["open spotify", "close chrome"]},
        {"name": "Environments", "desc": "Open/close a whole bundle of apps, folders and URLs at once.",
         "say": ["activate work environment", "close work environment"]},
        {"name": "Audio outputs", "desc": "Switch the playback device by phrase or by name.",
         "say": ["change to output 1", "switch output to headphones"]},
    ]},
    {"category": "Windows", "icon": "🪟", "items": [
        {"name": "Move / focus windows", "desc": "Move apps between monitors, focus, minimize, maximize.",
         "say": ["move discord to the left monitor", "minimize everything except vs code", "maximize chrome"]},
    ]},
    {"category": "Screen & vision", "icon": "👁", "items": [
        {"name": "Screenshot", "desc": "Capture one or both monitors.",
         "say": ["take a screenshot", "capture both monitors"]},
        {"name": "Describe my screen", "desc": "Wivexx looks at the screen and tells you what's on it.",
         "say": ["what's on my screen"]},
        {"name": "Number the screen / click", "desc": "Draw numbered badges over clickable controls, then click one by number.",
         "say": ["number the screen", "click 3"]},
    ]},
    {"category": "Web & info", "icon": "🌐", "items": [
        {"name": "Web search", "desc": "Answers factual questions with a live web lookup.",
         "say": ["who won the game last night", "what's the latest on …"]},
        {"name": "Weather", "desc": "Current conditions / forecast for a city.", "say": ["what's the weather", "weather in Tokyo tomorrow"]},
        {"name": "Time & date", "desc": "Local time and date.", "say": ["what time is it", "what's today's date"]},
        {"name": "YouTube", "desc": "Open or search YouTube.", "say": ["play lofi on youtube"]},
        {"name": "Battery / joke", "desc": "Battery status, or a quick joke.", "say": ["battery status", "tell me a joke"]},
    ]},
    {"category": "Quick local tools", "icon": "⚡", "items": [
        {"name": "Calculate & convert", "desc": "Math, percentages, units and live currency — spends no API tokens.",
         "say": ["what's 15% of 850", "convert 10 km to miles", "1500 usd to euros"]},
        {"name": "Clipboard", "desc": "Summarize, translate, rewrite, fix, shorten, read or clear your clipboard.",
         "say": ["summarize what I just copied", "translate my clipboard to spanish", "fix my clipboard"]},
    ]},
    {"category": "Timers & system", "icon": "⏱", "items": [
        {"name": "Timers & alarms", "desc": "Set timers; check time remaining.",
         "say": ["set a timer for 10 minutes", "timer status"]},
        {"name": "Volume", "desc": "Raise, lower, mute or set the system volume.", "say": ["volume up", "set volume to 30"]},
        {"name": "Shutdown", "desc": "Shut down the PC, optionally after a delay (asks you to confirm first).",
         "say": ["shut down the pc in 30 minutes", "cancel shutdown"]},
    ]},
    {"category": "Calendar", "icon": "📅", "items": [
        {"name": "Read calendar", "desc": "Your meetings today / next / on a given day.",
         "say": ["what's my first meeting tomorrow", "what's on my calendar today"]},
        {"name": "Book events", "desc": "Create events and focus blocks by voice.",
         "say": ["schedule a client call tomorrow at 3pm for an hour"]},
    ]},
    {"category": "Goals & to-do", "icon": "🎯", "items": [
        {"name": "Manage goals", "desc": "Add, complete and review goals with priorities, due dates and reminders.",
         "say": ["what are my goals", "add goal buy ND filters", "complete goal buy ND filters"]},
        {"name": "Today-focus overlay", "desc": "Pin a small always-on-top panel with today's focus.",
         "say": ["toggle desktop overlay"]},
    ]},
    {"category": "Memory", "icon": "🧠", "items": [
        {"name": "Remember facts", "desc": "Tell Wivexx things to remember; it recalls them by meaning later.",
         "say": ["remember that I shoot on a Canon R6", "what do you remember about me"]},
        {"name": "Wipe memory", "desc": "Clear stored facts (asks you to confirm first).", "say": ["wipe your memory"]},
    ]},
    {"category": "Creator tools", "icon": "✍", "items": [
        {"name": "Caption studio", "desc": "Write post captions with per-platform researched hashtags from your photo/video.",
         "say": ["create a caption"]},
        {"name": "Social trackers", "desc": "Track Instagram accounts and report growth, engagement and latest-post performance.",
         "say": ["track instagram <handle>", "social media report"]},
        {"name": "Client photo delivery", "desc": "Develop ARW→JPG, rename in sequence, upload to a public Google Drive gallery.",
         "say": ["deliver photos to a client", "convert my ARW to JPG"]},
        {"name": "Transcribe media", "desc": "Turn any audio or video file into text plus an .srt subtitle file — supports mp3, mp4, mkv, mov, wav, ogg, m4a, webm and many more. Runs locally with Whisper (no internet, no API). Pick the file and Wivexx saves the transcript next to it.",
         "say": ["transcribe a file", "transcribe this video", "make a transcript"]},
    ]},
    {"category": "Storage", "icon": "💾", "items": [
        {"name": "Analyze drives", "desc": "Find the biggest unused files; warns when a drive gets full.",
         "say": ["analyze my drives", "what's taking up my space"]},
        {"name": "Auto-import", "desc": "Auto-copy photos/videos from an allowed SD card / USB drive on connect.", "say": []},
    ]},
    {"category": "Notes, requests & usage", "icon": "📝", "items": [
        {"name": "Save a note", "desc": "Jot a quick note.", "say": ["make a note that …"]},
        {"name": "Feature requests", "desc": "Dictate a feature request for Wivexx itself.", "say": ["I have a request"]},
        {"name": "Save conversation", "desc": "Export the current conversation to a file.", "say": ["save the conversation"]},
        {"name": "API usage", "desc": "Today's API calls and cost.", "say": ["how much have I spent today"]},
    ]},
    {"category": "Modes & access", "icon": "🛠", "items": [
        {"name": "Work mode", "desc": "Auto-extract finished Downloads zips into their folders. Say \"import to Lightroom\" to open the newest in Lightroom Classic.",
         "say": ["enable work mode", "import to lightroom"]},
        {"name": "Voice biometrics", "desc": "Enroll your voice for identification. (Voice-gating of sensitive commands is currently turned off.)", "say": ["enroll my voice"]},
        {"name": "Phone & online control", "desc": "Drive Wivexx from your phone on the LAN, or from wivexx.com/ai when signed in.", "say": []},
        {"name": "Status overlay", "desc": "A small always-on-top widget: state, timers, today's API cost.", "say": ["show the status overlay"]},
    ]},
]


def categories() -> list:
    """The full catalog (for the in-app panel)."""
    return CATALOG


def flat() -> list:
    """All items as a flat list of (category, name, desc, say)."""
    out = []
    for c in CATALOG:
        for it in c["items"]:
            out.append({"category": c["category"], **it})
    return out


def system_prompt_summary() -> str:
    """A compact, accurate description of Wivexx's abilities for the Claude system
    prompt — so the assistant answers truthfully when asked what it can do."""
    lines = [f"You are Wivexx (v{VERSION}), a Windows voice assistant. Your real, "
             "implemented capabilities are below — when asked what you can do, or "
             "whether you can do something, answer from THIS list (don't invent "
             "abilities you don't have, and don't deny ones you do):"]
    for c in CATALOG:
        names = "; ".join(it["name"] for it in c["items"])
        lines.append(f"- {c['category']}: {names}.")
    lines.append("Each ability is triggered by natural speech or the typed input. "
                 "Detailed commands and examples live in the in-app Capabilities panel.")
    return "\n".join(lines)


def spoken_summary() -> str:
    """A short, friendly spoken answer to 'what can you do?'."""
    cats = ", ".join(c["category"].lower() for c in CATALOG[:-1])
    last = CATALOG[-1]["category"].lower()
    return (f"Quite a lot, sir. Across {len(CATALOG)} areas — {cats}, and {last}. "
            "For the full list with example phrases, open the Capabilities panel "
            "in the control room, or ask me about any one of them.")
