//! Conversational shortcut handler — only AcknowledgementShortcut survives.
//!
//! All other conversational shortcuts (CapabilitySummary, PersonalityProfile,
//! ProviderInventory) were retired in v0.11.1. See docs/architecture/shortcut-registry.md.

use super::super::core::InferenceOutput;
use super::super::intent_registry::Intent;
use super::{ShortcutContext, ShortcutHandler, shortcut_output};

// ── Acknowledgement (always eligible, no cache bypass) ──────────────────

pub struct AcknowledgementShortcut;

#[async_trait::async_trait]
impl ShortcutHandler for AcknowledgementShortcut {
    fn handles(&self, intents: &[Intent]) -> bool {
        intents.contains(&Intent::Acknowledgement)
    }

    fn requires_cache_bypass(&self) -> bool {
        false
    }

    fn execution_confidence(&self, ctx: &ShortcutContext) -> (f64, &'static str) {
        // Acknowledgement fires on very short, explicit confirmation phrases.
        // High confidence from brevity + common ack patterns.
        let trimmed = ctx.user_content.trim();
        let word_count = trimmed.split_whitespace().count();
        if word_count <= 3 {
            let lower = trimmed.to_ascii_lowercase();
            let ack_phrases = [
                "ok",
                "okay",
                "got it",
                "understood",
                "noted",
                "acknowledged",
                "roger",
                "copy",
                "ack",
                "yep",
                "yes",
                "sure",
                "thanks",
                "thank you",
                "ty",
            ];
            if ack_phrases
                .iter()
                .any(|p| lower == *p || lower.starts_with(p))
            {
                return (1.0, "short explicit acknowledgment phrase");
            }
        }
        (0.0, "not a clear acknowledgment")
    }

    async fn execute(
        &self,
        ctx: &mut ShortcutContext<'_>,
    ) -> Result<Option<InferenceOutput>, String> {
        Ok(Some(shortcut_output(
            ctx.prepared_model,
            "Acknowledged, awaiting your next instruction.".to_string(),
            1.0,
            vec![],
            ctx.turn_id,
        )))
    }
}
