/*
 * 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 { recordDecompositionVote } from '../../../services/decomposition.js';
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@jterrats/setup-agents', 'setup-agents.workflow.decompose');
export default class WorkflowDecompose extends SfCommand {
    static summary = messages.getMessage('summary');
    static description = messages.getMessage('description');
    static examples = messages.getMessages('examples');
    static flags = {
        story: Flags.string({
            char: 't',
            summary: messages.getMessage('flags.story.summary'),
            description: messages.getMessage('flags.story.description'),
            required: true,
        }),
        voter: Flags.option({
            options: ['ba', 'ta'],
            summary: messages.getMessage('flags.voter.summary'),
            description: messages.getMessage('flags.voter.description'),
            required: true,
        })(),
        verdict: Flags.option({
            options: ['proceed', 'decompose'],
            summary: messages.getMessage('flags.verdict.summary'),
            description: messages.getMessage('flags.verdict.description'),
            required: true,
        })(),
        reason: Flags.string({
            summary: messages.getMessage('flags.reason.summary'),
            description: messages.getMessage('flags.reason.description'),
            required: true,
        }),
        splits: Flags.string({
            summary: messages.getMessage('flags.splits.summary'),
            description: messages.getMessage('flags.splits.description'),
            multiple: true,
        }),
    };
    async run() {
        const { flags } = await this.parse(WorkflowDecompose);
        const cwd = process.cwd();
        const vote = {
            voter: flags.voter,
            verdict: flags.verdict,
            reason: flags.reason,
            suggestedSplits: flags.splits ?? [],
        };
        const { state } = recordDecompositionVote(cwd, flags.story, vote);
        if (state.consensus === 'decompose') {
            this.log(messages.getMessage('info.decompose', [flags.story]));
            if (state.suggestedSplits.length > 0) {
                this.log(messages.getMessage('info.splits', [state.suggestedSplits.join(', ')]));
            }
        }
        else if (state.consensus === 'proceed') {
            this.log(messages.getMessage('info.proceed', [flags.story]));
        }
        else {
            this.log(messages.getMessage('info.pending', [state.pendingVoter ?? 'unknown']));
        }
        return {
            taskId: flags.story,
            vote,
            consensus: state.consensus,
            pendingVoter: state.pendingVoter,
            suggestedSplits: state.suggestedSplits,
        };
    }
}
//# sourceMappingURL=decompose.js.map