import { join } from 'node:path';
import { copyDirWithStatus as defaultCopyDirWithStatus, copyDirWithVersionCheck as defaultCopyDirWithVersionCheck, } from '../../../init/tools/shared/copy-helpers.js';
import { CORE_SKILLS } from '../../../init/tools/shared/skill-manifest.js';
import { dirExists as defaultDirExists } from '../../../../fs/io.js';
export { CORE_SKILLS };
const defaultDependencies = {
    copyDirWithVersionCheck: defaultCopyDirWithVersionCheck,
    copyDirWithStatus: defaultCopyDirWithStatus,
    dirExists: defaultDirExists,
};
export async function installCore(options) {
    const force = options.force ?? false;
    const deps = options.dependencies ?? defaultDependencies;
    const result = {
        copiedSkills: [],
        updatedSkills: [],
        skippedSkills: [],
        outdatedSkills: [],
        docsStatus: 'skipped',
    };
    for (const skill of CORE_SKILLS) {
        const source = join(options.assetsRoot, 'skills', skill);
        const destination = join(options.targetRoot, '.agents', 'skills', skill);
        const copyResult = await deps.copyDirWithVersionCheck(source, destination, force);
        if (copyResult.status === 'copied') {
            result.copiedSkills.push(skill);
        }
        else if (copyResult.status === 'updated') {
            result.updatedSkills.push(skill);
        }
        else if (copyResult.status === 'outdated') {
            result.outdatedSkills.push({
                name: skill,
                installed: copyResult.installedVersion ?? null,
                bundled: copyResult.bundledVersion ?? null,
            });
        }
        else {
            result.skippedSkills.push(skill);
        }
    }
    // Copy docs to ~/.oat/docs/
    const docsSource = join(options.assetsRoot, 'docs');
    const docsDestination = join(options.targetRoot, '.oat', 'docs');
    const docsExist = await deps.dirExists(docsSource);
    if (docsExist) {
        result.docsStatus = await deps.copyDirWithStatus(docsSource, docsDestination, force);
    }
    return result;
}
