//! `adom-usb install` — deploy the user-facing skill so Claude Code discovers
//! the dashboard, mirroring the adom-parts-search install flow.

use crate::{note, ok};
use std::fs;
use std::path::PathBuf;

// SAFETY NET -- do not rely on for release propagation. On publish, `install`
// should fetch SKILL.md from the wiki as the primary source; this baked copy is
// only the offline fallback when the wiki is unreachable.
const SKILL_MD: &str = include_str!("../skills/adom-usb/SKILL.md");
// The wiki-publish skill travels with the repo so the naming/hero/publish
// conventions for the whole Adom USB family are never lost.
const PUBLISH_SKILL_MD: &str = include_str!("../skills/adom-usb-publish/SKILL.md");

fn skills_root() -> PathBuf {
    let home = std::env::var("HOME").unwrap_or_else(|_| "/root".into());
    PathBuf::from(home).join(".claude/skills")
}

pub fn install() -> Result<(), String> {
    for (name, body) in [("adom-usb", SKILL_MD), ("adom-usb-publish", PUBLISH_SKILL_MD)] {
        let dir = skills_root().join(name);
        fs::create_dir_all(&dir).map_err(|e| format!("create {}: {}", dir.display(), e))?;
        let dest = dir.join("SKILL.md");
        fs::write(&dest, body).map_err(|e| format!("write {}: {}", dest.display(), e))?;
        ok(format!("installed skill → {}", dest.display()));
    }
    note!("  run `adom-usb app --demo` to open the dashboard");
    Ok(())
}