import { join } from 'node:path';
import { copyDirWithVersionCheck, copyFileWithStatus, } from '../../../init/tools/shared/copy-helpers.js';
import { RESEARCH_AGENTS, RESEARCH_SKILLS, } from '../../../init/tools/shared/skill-manifest.js';
export { RESEARCH_AGENTS, RESEARCH_SKILLS };
export async function installResearch(options) {
    const force = options.force ?? false;
    const result = {
        copiedSkills: [],
        updatedSkills: [],
        skippedSkills: [],
        outdatedSkills: [],
        copiedAgents: [],
        updatedAgents: [],
        skippedAgents: [],
    };
    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 agent of RESEARCH_AGENTS) {
        const source = join(options.assetsRoot, 'agents', agent);
        const destination = join(options.targetRoot, '.agents', 'agents', agent);
        const copyStatus = await copyFileWithStatus(source, destination, force);
        if (copyStatus === 'copied') {
            result.copiedAgents.push(agent);
        }
        else if (copyStatus === 'updated') {
            result.updatedAgents.push(agent);
        }
        else {
            result.skippedAgents.push(agent);
        }
    }
    return result;
}
