/*
 * 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 { recordPath, requestReview } 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.review.request');
const PROFILE_HELP_VALUE = ALL_PROFILES.map((profile) => profile.id).join('|');
export default class ReviewRequest 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'),
        }),
        requester: Flags.string({
            summary: messages.getMessage('flags.requester.summary'),
            description: messages.getMessage('flags.requester.description'),
            helpValue: PROFILE_HELP_VALUE,
            default: 'developer',
        }),
        reviewer: Flags.string({
            summary: messages.getMessage('flags.reviewer.summary'),
            description: messages.getMessage('flags.reviewer.description'),
            helpValue: PROFILE_HELP_VALUE,
        }),
        gate: Flags.string({
            summary: messages.getMessage('flags.gate.summary'),
            description: messages.getMessage('flags.gate.description'),
        }),
        evidence: Flags.string({
            summary: messages.getMessage('flags.evidence.summary'),
            description: messages.getMessage('flags.evidence.description'),
        }),
    };
    async run() {
        const { flags } = await this.parse(ReviewRequest);
        const cwd = process.cwd();
        const record = requestReview(cwd, {
            summary: flags.summary,
            requester: flags.requester,
            reviewer: flags.reviewer,
            gates: splitCsv(flags.gate),
            taskIds: toTaskIds(flags.task),
            evidenceIds: splitCsv(flags.evidence),
        });
        const file = recordPath(cwd, 'review');
        this.log(messages.getMessage('info.created', [record.id, file]));
        return { record, file, cwd };
    }
}
function toTaskIds(task) {
    return task ? [task] : [];
}
//# sourceMappingURL=request.js.map