/*
 * 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 { Messages } from '@salesforce/core';
import { Flags, SfCommand } from '@salesforce/sf-plugins-core';
import { ALL_PROFILES } from '../../../profiles/index.js';
import { addDecisionRecord, recordPath } from '../../../services/orchestration-records.js';
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@jterrats/setup-agents', 'setup-agents.decision.add');
const PROFILE_HELP_VALUE = ALL_PROFILES.map((profile) => profile.id).join('|');
const DECISION_STATUSES = ['proposed', 'accepted', 'superseded'];
export default class DecisionAdd extends SfCommand {
    static summary = messages.getMessage('summary');
    static description = messages.getMessage('description');
    static examples = messages.getMessages('examples');
    static flags = {
        summary: Flags.string({
            char: 's',
            summary: messages.getMessage('flags.summary.summary'),
            description: messages.getMessage('flags.summary.description'),
            required: true,
        }),
        task: Flags.string({
            char: 't',
            summary: messages.getMessage('flags.task.summary'),
            description: messages.getMessage('flags.task.description'),
        }),
        role: Flags.string({
            char: 'r',
            summary: messages.getMessage('flags.role.summary'),
            description: messages.getMessage('flags.role.description'),
            default: 'developer',
        }),
        profile: Flags.string({
            char: 'p',
            summary: messages.getMessage('flags.profile.summary'),
            description: messages.getMessage('flags.profile.description'),
            helpValue: PROFILE_HELP_VALUE,
        }),
        rationale: Flags.string({
            summary: messages.getMessage('flags.rationale.summary'),
            description: messages.getMessage('flags.rationale.description'),
        }),
        status: Flags.string({
            summary: messages.getMessage('flags.status.summary'),
            description: messages.getMessage('flags.status.description'),
            options: [...DECISION_STATUSES],
            default: 'accepted',
        }),
        outcome: Flags.string({
            summary: messages.getMessage('flags.outcome.summary'),
            description: messages.getMessage('flags.outcome.description'),
        }),
        alternative: Flags.string({
            summary: messages.getMessage('flags.alternative.summary'),
            description: messages.getMessage('flags.alternative.description'),
        }),
        evidence: Flags.string({
            summary: messages.getMessage('flags.evidence.summary'),
            description: messages.getMessage('flags.evidence.description'),
        }),
    };
    async run() {
        const { flags } = await this.parse(DecisionAdd);
        const cwd = process.cwd();
        const record = addDecisionRecord(cwd, {
            summary: flags.summary,
            profile: flags.profile ?? flags.role,
            taskIds: toTaskIds(flags.task),
            rationale: flags.rationale,
            outcome: flags.outcome ?? flags.status,
            alternatives: splitCsv(flags.alternative),
            evidenceIds: splitCsv(flags.evidence),
        });
        const file = recordPath(cwd, 'decision');
        this.log(messages.getMessage('info.created', [record.id, file]));
        return { record, file, cwd };
    }
}
function toTaskIds(task) {
    return task ? [task] : [];
}
function splitCsv(value) {
    return value
        ? value
            .split(',')
            .map((entry) => entry.trim())
            .filter(Boolean)
        : [];
}
//# sourceMappingURL=add.js.map