import path from "node:path";
import { normalizeAppFlags } from "../constants.js";
import { createId, toNameFromPath } from "../utils/id.js";
export function buildSkillFromInput(input) {
    return {
        id: createId("skill"),
        name: input.name ?? toNameFromPath(input.sourceDir),
        directory: input.sourceDir,
        description: input.description,
        apps: normalizeAppFlags(input.apps),
        installedAt: Date.now(),
    };
}
export function mergeSkill(current, patch) {
    return {
        ...current,
        name: patch.name ?? current.name,
        description: patch.description ?? current.description,
        apps: patch.apps
            ? {
                ...current.apps,
                ...normalizeAppFlags({ ...current.apps, ...patch.apps }),
            }
            : current.apps,
    };
}
export function skillSourceDir(ssotSkillsDir, skill) {
    return path.join(ssotSkillsDir, skill.id);
}
export function applySkillAppFlag(skill, appId, enabled) {
    const canonicalAppId = appId === "claude" ? "claudecode" : appId;
    const apps = {
        ...skill.apps,
        [canonicalAppId]: enabled,
        claude: false,
    };
    return {
        ...skill,
        apps,
    };
}
