import { join } from 'node:path';
import { copyDirWithVersionCheck, copyFileWithStatus, } from '../../../init/tools/shared/copy-helpers.js';
import { PROJECT_MANAGEMENT_SCRIPTS, PROJECT_MANAGEMENT_SKILLS, PROJECT_MANAGEMENT_TEMPLATES, } from '../../../init/tools/shared/skill-manifest.js';
export { PROJECT_MANAGEMENT_SCRIPTS, PROJECT_MANAGEMENT_SKILLS, PROJECT_MANAGEMENT_TEMPLATES, };
export async function installProjectManagement(options) {
    const force = options.force ?? false;
    const result = {
        copiedSkills: [],
        updatedSkills: [],
        skippedSkills: [],
        outdatedSkills: [],
        copiedTemplates: [],
        updatedTemplates: [],
        skippedTemplates: [],
    };
    for (const skill of PROJECT_MANAGEMENT_SKILLS) {
        const source = join(options.assetsRoot, 'skills', skill);
        const destination = join(options.targetRoot, '.agents', 'skills', skill);
        const copyResult = await 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);
        }
    }
    for (const template of PROJECT_MANAGEMENT_TEMPLATES) {
        const source = join(options.assetsRoot, 'templates', template);
        const destination = join(options.targetRoot, '.oat', 'templates', template);
        const copyStatus = await copyFileWithStatus(source, destination, force);
        if (copyStatus === 'copied') {
            result.copiedTemplates.push(template);
        }
        else if (copyStatus === 'updated') {
            result.updatedTemplates.push(template);
        }
        else {
            result.skippedTemplates.push(template);
        }
    }
    return result;
}
