/*
 * 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 { resolveWorkspaceRoot } from '../../../services/workspace-root.js';
import { workspaceFlags } from '../../../util/task-flags.js';
import { ALL_PROFILES } from '../../../profiles/index.js';
import { completeReview, recordPath } from '../../../services/orchestration-records.js';
import { PHASE_SEQUENCE } from '../../../services/workflow-instructions.js';
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@jterrats/setup-agents', 'setup-agents.review.complete');
const PROFILE_HELP_VALUE = ALL_PROFILES.map((profile) => profile.id).join('|');
const REVIEW_RESULTS = ['approved', 'blocked', 'changes'];
export default class ReviewComplete extends SfCommand {
    static summary = messages.getMessage('summary');
    static description = messages.getMessage('description');
    static examples = messages.getMessages('examples');
    static flags = {
        ...workspaceFlags,
        id: Flags.string({
            summary: messages.getMessage('flags.id.summary'),
            description: messages.getMessage('flags.id.description'),
            required: true,
        }),
        result: Flags.string({
            summary: messages.getMessage('flags.result.summary'),
            description: messages.getMessage('flags.result.description'),
            options: [...REVIEW_RESULTS],
            required: true,
        }),
        reviewer: Flags.string({
            summary: messages.getMessage('flags.reviewer.summary'),
            description: messages.getMessage('flags.reviewer.description'),
            helpValue: PROFILE_HELP_VALUE,
        }),
        findings: Flags.string({
            summary: messages.getMessage('flags.findings.summary'),
            description: messages.getMessage('flags.findings.description'),
        }),
        recommendation: Flags.string({
            summary: messages.getMessage('flags.recommendation.summary'),
            description: messages.getMessage('flags.recommendation.description'),
        }),
        'return-to': Flags.string({
            summary: messages.getMessage('flags.return-to.summary'),
            description: messages.getMessage('flags.return-to.description'),
            options: [...PHASE_SEQUENCE],
        }),
    };
    async run() {
        const { flags } = await this.parse(ReviewComplete);
        const cwd = resolveWorkspaceRoot(flags);
        const result = completeReview(cwd, {
            id: flags.id,
            result: flags.result,
            reviewer: flags.reviewer,
            findings: flags.findings,
            recommendation: flags.recommendation,
            returnTarget: flags['return-to'],
        });
        if (!result.ok)
            throw new Error(result.error.message);
        const record = result.value;
        const file = recordPath(cwd, 'review');
        this.log(messages.getMessage('info.completed', [record.id, record.status, file]));
        return { record, file, cwd };
    }
}
//# sourceMappingURL=complete.js.map