/*
 * 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 { addHandoffRecord, recordPath } from '../../../services/orchestration-records.js';
import { splitCsv } from '../../../util/task-flags.js';
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@jterrats/setup-agents', 'setup-agents.handoff.create');
const PROFILE_HELP_VALUE = ALL_PROFILES.map((profile) => profile.id).join('|');
export default class HandoffCreate 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,
        }),
        from: Flags.string({
            summary: messages.getMessage('flags.from.summary'),
            description: messages.getMessage('flags.from.description'),
            required: true,
        }),
        to: Flags.string({
            summary: messages.getMessage('flags.to.summary'),
            description: messages.getMessage('flags.to.description'),
            required: true,
        }),
        files: Flags.string({
            summary: messages.getMessage('flags.files.summary'),
            description: messages.getMessage('flags.files.description'),
        }),
        'changed-file': Flags.string({
            summary: messages.getMessage('flags.changed-file.summary'),
            description: messages.getMessage('flags.changed-file.description'),
        }),
        risks: Flags.string({
            summary: messages.getMessage('flags.risks.summary'),
            description: messages.getMessage('flags.risks.description'),
        }),
        risk: Flags.string({
            summary: messages.getMessage('flags.risk.summary'),
            description: messages.getMessage('flags.risk.description'),
        }),
        'next-actions': Flags.string({
            summary: messages.getMessage('flags.next-actions.summary'),
            description: messages.getMessage('flags.next-actions.description'),
        }),
        'next-action': Flags.string({
            summary: messages.getMessage('flags.next-action.summary'),
            description: messages.getMessage('flags.next-action.description'),
        }),
        evidence: Flags.string({
            summary: messages.getMessage('flags.evidence.summary'),
            description: messages.getMessage('flags.evidence.description'),
        }),
        acceptance: Flags.string({
            summary: messages.getMessage('flags.acceptance.summary'),
            description: messages.getMessage('flags.acceptance.description'),
        }),
        'capability-signals': Flags.string({
            summary: messages.getMessage('flags.capability-signals.summary'),
            description: messages.getMessage('flags.capability-signals.description'),
            helpValue: 'qa evidence,release evidence',
        }),
    };
    async run() {
        const { flags } = await this.parse(HandoffCreate);
        const cwd = process.cwd();
        const record = addHandoffRecord(cwd, {
            summary: flags.summary,
            taskIds: toTaskIds(flags.task),
            from: flags.from,
            to: flags.to,
            changedFiles: splitCsv(flags['changed-file'] ?? flags.files),
            risks: splitCsv(flags.risk ?? flags.risks),
            nextActions: splitCsv(flags['next-action'] ?? flags['next-actions']),
            acceptanceCriteria: splitCsv(flags.acceptance),
            capabilitySignals: splitCsv(flags['capability-signals']),
            evidenceIds: splitCsv(flags.evidence),
        });
        const file = recordPath(cwd, 'handoff');
        this.log(messages.getMessage('info.created', [record.id, file]));
        return { record, file, cwd };
    }
}
function toTaskIds(task) {
    return task ? [task] : [];
}
//# sourceMappingURL=create.js.map