/*
 * 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 { clarificationPath, openClarification } from '../../../services/clarification.js';
import { readWorkflowRun } from '../../../services/workflow-engine.js';
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@jterrats/setup-agents', 'setup-agents.workflow.clarify');
const ALLOWED_FROM_ROLES = ['developer', 'qa'];
const ALLOWED_TO_ROLES = ['po', 'ta'];
export default class WorkflowClarify extends SfCommand {
    static summary = messages.getMessage('summary');
    static description = messages.getMessage('description');
    static examples = messages.getMessages('examples');
    static flags = {
        run: Flags.string({
            summary: messages.getMessage('flags.run.summary'),
            description: messages.getMessage('flags.run.description'),
            required: true,
        }),
        from: Flags.string({
            summary: messages.getMessage('flags.from.summary'),
            description: messages.getMessage('flags.from.description'),
            options: [...ALLOWED_FROM_ROLES],
            required: true,
        }),
        to: Flags.string({
            summary: messages.getMessage('flags.to.summary'),
            description: messages.getMessage('flags.to.description'),
            options: [...ALLOWED_TO_ROLES],
            required: true,
        }),
        question: Flags.string({
            summary: messages.getMessage('flags.question.summary'),
            description: messages.getMessage('flags.question.description'),
            required: true,
        }),
    };
    async run() {
        const { flags } = await this.parse(WorkflowClarify);
        const cwd = process.cwd();
        const fromRole = flags.from;
        const toRole = flags.to;
        const existingRun = readWorkflowRun(cwd, flags.run);
        if (!existingRun) {
            throw new Error(messages.getMessage('errors.run-not-found', [flags.run]));
        }
        const storyId = existingRun.storyId;
        const { record, run } = openClarification(cwd, {
            runId: flags.run,
            storyId,
            fromRole,
            toRole,
            question: flags.question,
        });
        const file = clarificationPath(cwd);
        this.log(messages.getMessage('info.created', [record.id, toRole, file]));
        this.log(messages.getMessage('info.respond-hint', [flags.run, record.id]));
        return { record, run, file, cwd };
    }
}
//# sourceMappingURL=clarify.js.map