/*
 * Copyright 2026, Jaime Terrats.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import { existsSync } from 'node:fs';
import { join } from 'node:path';
import { ensureDir } from '../services/file-writer.js';
export function setupOpenOrchestraIntegration(cwd, profiles, writer) {
    const dir = join(cwd, '.setup-agents', 'open-orchestra');
    ensureDir(dir);
    const files = {
        'README.md': readme(),
        'profiles.json': JSON.stringify({ profiles: profiles.map(profileMapping) }, null, 2) + '\n',
    };
    for (const [filename, content] of Object.entries(files)) {
        writer.write(join(dir, filename), content);
    }
    const available = isOpenOrchestraAvailable(cwd);
    return {
        enabled: true,
        status: available ? 'available' : 'not-installed',
        path: dir,
        files: Object.keys(files),
        command: 'orchestra init',
        guidance: available
            ? 'Open Orchestra appears to be available. Run `orchestra init` when you want to create the runtime workflow state.'
            : 'Open Orchestra is not installed for this workspace. Install or link it, then run `orchestra init` when ready.',
    };
}
function isOpenOrchestraAvailable(cwd) {
    return existsSync(join(cwd, 'node_modules', '.bin', 'orchestra'));
}
const PROFILE_TO_ROLE = { ba: 'business_analyst', pm: 'product_manager' };
function profileMapping(profile) {
    return {
        id: profile.id,
        label: profile.label,
        ruleFile: profile.ruleFile,
        suggestedRole: PROFILE_TO_ROLE[profile.id] ?? profile.id,
        activationCriteria: profile.orchestration?.activationCriteria ?? [],
        expectedEvidence: profile.orchestration?.expectedEvidence ?? [],
        gates: profile.orchestration?.gates ?? [],
    };
}
function readme() {
    return [
        '# Open Orchestra Integration',
        '',
        'This directory is generated by `setup-agents` only when Open Orchestra integration is explicitly requested.',
        '',
        '## Boundary',
        '',
        '- `setup-agents` installs Salesforce-focused agent rules, profiles, skills, and local state scaffolding.',
        '- Open Orchestra owns runtime orchestration: task graphs, locks, reviews, evidence, gates, budgets, and provenance.',
        '- This integration does not make Open Orchestra a required dependency of `setup-agents`.',
        '',
        '## Next Step',
        '',
        'Run this only when you want Open Orchestra to create runtime workflow state:',
        '',
        '```sh',
        'orchestra init',
        '```',
        '',
        'If `orchestra` is not available, install or link Open Orchestra first.',
        '',
        '## Files',
        '',
        '- `profiles.json` maps selected setup-agents profiles to Open Orchestra-compatible role hints, activation criteria, expected evidence, and gates.',
    ].join('\n');
}
//# sourceMappingURL=open-orchestra.js.map