/*
 * 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 { checkAndRecordBiasLessons, closeSprint, sprintPath } from '../../../../services/workflow-velocity.js';
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@jterrats/setup-agents', 'setup-agents.workflow.sprint.close');
const PCT_LABEL = (pct) => {
    if (pct == null)
        return '—';
    const sign = pct <= 0 ? '' : '+';
    return `${sign}${pct}%`;
};
export default class WorkflowSprintClose extends SfCommand {
    static summary = messages.getMessage('summary');
    static description = messages.getMessage('description');
    static examples = messages.getMessages('examples');
    static flags = {
        sprint: Flags.string({
            summary: messages.getMessage('flags.sprint.summary'),
            description: messages.getMessage('flags.sprint.description'),
            required: true,
        }),
        'committed-points': Flags.integer({
            summary: messages.getMessage('flags.committed-points.summary'),
            description: messages.getMessage('flags.committed-points.description'),
            required: true,
        }),
    };
    async run() {
        const { flags } = await this.parse(WorkflowSprintClose);
        const cwd = process.cwd();
        const file = sprintPath(cwd);
        const record = closeSprint(cwd, {
            sprintId: flags.sprint,
            committedPoints: flags['committed-points'],
        });
        this.log(messages.getMessage('info.closed', [
            record.sprintId,
            record.committedPoints ?? 0,
            record.actualPoints ?? 0,
            PCT_LABEL(record.velocityPct),
            PCT_LABEL(record.avgVsSoloPct),
            PCT_LABEL(record.avgVsAiUnguidedPct),
        ]));
        const lessons = checkAndRecordBiasLessons(cwd);
        if (lessons.length > 0) {
            this.log(messages.getMessage('info.lessons', [lessons.length]));
            for (const lesson of lessons) {
                this.log(`  [${lesson.role}] ${lesson.biasDirection} bias avg=${lesson.biasAvgPct}% stories=${lesson.storySample.join(',')}`);
            }
        }
        return { record, lessons, file, cwd };
    }
}
//# sourceMappingURL=close.js.map