/*
 * 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 { sprintPath, velocityTrend } from '../../../../services/workflow-velocity.js';
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@jterrats/setup-agents', 'setup-agents.workflow.sprint.velocity');
const PCT_LABEL = (pct) => {
    if (pct == null)
        return '—';
    const sign = pct <= 0 ? '' : '+';
    return `${sign}${pct}%`;
};
const col = (s, w) => s.padEnd(w).slice(0, w);
export default class WorkflowSprintVelocity extends SfCommand {
    static summary = messages.getMessage('summary');
    static description = messages.getMessage('description');
    static examples = messages.getMessages('examples');
    static flags = {
        limit: Flags.integer({
            summary: messages.getMessage('flags.limit.summary'),
            description: messages.getMessage('flags.limit.description'),
            default: 5,
        }),
    };
    async run() {
        const { flags } = await this.parse(WorkflowSprintVelocity);
        const cwd = process.cwd();
        const file = sprintPath(cwd);
        const sprints = velocityTrend(cwd, flags.limit);
        if (!this.jsonEnabled()) {
            if (sprints.length === 0) {
                this.log(messages.getMessage('info.empty'));
                return { sprints, file, cwd };
            }
            const header = `${col('Sprint', 16)} ${col('Committed', 10)} ${col('Actual', 8)} ${col('Velocity%', 10)} ${col('AvgVsSolo', 10)} ${col('AvgVsAI', 10)}`;
            this.log(header);
            this.log('─'.repeat(header.length));
            for (const s of sprints) {
                this.log(`${col(s.sprintId, 16)} ${col(String(s.committedPoints ?? '—'), 10)} ${col(String(s.actualPoints ?? '—'), 8)} ${col(PCT_LABEL(s.velocityPct), 10)} ${col(PCT_LABEL(s.avgVsSoloPct), 10)} ${col(PCT_LABEL(s.avgVsAiUnguidedPct), 10)}`);
            }
        }
        return { sprints, file, cwd };
    }
}
//# sourceMappingURL=velocity.js.map