import { join } from 'node:path';
import { copyDirWithVersionCheck, copyFileWithStatus, } from '../../../init/tools/shared/copy-helpers.js';
import { DOCS_SCRIPTS, DOCS_SKILLS, } from '../../../init/tools/shared/skill-manifest.js';
import { fileExists } from '../../../../fs/io.js';
export { DOCS_SCRIPTS, DOCS_SKILLS };
export async function installDocs(options) {
    const force = options.force ?? false;
    const result = {
        copiedSkills: [],
        updatedSkills: [],
        skippedSkills: [],
        outdatedSkills: [],
        copiedScripts: [],
        updatedScripts: [],
        skippedScripts: [],
    };
    for (const skill of options.skills) {
        const source = join(options.assetsRoot, 'skills', skill);
        const destination = join(options.targetRoot, '.agents', 'skills', skill);
        const resultWithVersion = await copyDirWithVersionCheck(source, destination, force);
        if (resultWithVersion.status === 'copied') {
            result.copiedSkills.push(skill);
        }
        else if (resultWithVersion.status === 'updated') {
            result.updatedSkills.push(skill);
        }
        else if (resultWithVersion.status === 'outdated') {
            result.outdatedSkills.push({
                name: skill,
                installed: resultWithVersion.installedVersion ?? null,
                bundled: resultWithVersion.bundledVersion ?? null,
            });
        }
        else {
            result.skippedSkills.push(skill);
        }
    }
    for (const script of DOCS_SCRIPTS) {
        const source = join(options.assetsRoot, 'scripts', script);
        const destination = join(options.targetRoot, '.oat', 'scripts', script);
        const sourceExists = await fileExists(source);
        if (!sourceExists) {
            result.skippedScripts.push(script);
            continue;
        }
        const copyStatus = await copyFileWithStatus(source, destination, force);
        if (copyStatus === 'copied') {
            result.copiedScripts.push(script);
        }
        else if (copyStatus === 'updated') {
            result.updatedScripts.push(script);
        }
        else {
            result.skippedScripts.push(script);
        }
    }
    return result;
}
