/*
 * 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 { dedupeById } from '../../../services/file-writer.js';
import { listRecords, recordPath } from '../../../services/orchestration-records.js';
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@jterrats/setup-agents', 'setup-agents.review.list');
const REVIEW_STATUSES = ['pending', 'approved', 'blocked', 'changes'];
export default class ReviewList extends SfCommand {
    static summary = messages.getMessage('summary');
    static description = messages.getMessage('description');
    static examples = messages.getMessages('examples');
    static flags = {
        status: Flags.string({
            summary: messages.getMessage('flags.status.summary'),
            description: messages.getMessage('flags.status.description'),
            options: [...REVIEW_STATUSES],
        }),
        task: Flags.string({
            char: 't',
            summary: messages.getMessage('flags.task.summary'),
            description: messages.getMessage('flags.task.description'),
        }),
        limit: Flags.integer({
            char: 'l',
            summary: messages.getMessage('flags.limit.summary'),
            description: messages.getMessage('flags.limit.description'),
            default: 20,
            min: 1,
        }),
    };
    async run() {
        const { flags } = await this.parse(ReviewList);
        const cwd = process.cwd();
        const all = listRecords(cwd, 'review');
        const latest = latestByReviewId(all);
        const records = latest
            .filter((r) => (flags.status ? r.status === flags.status : true))
            .filter((r) => (flags.task ? r.taskIds.includes(flags.task) : true))
            .slice(-flags.limit);
        if (records.length === 0) {
            this.log(messages.getMessage('info.empty'));
        }
        else {
            for (const record of records)
                this.log(formatRecord(record));
        }
        const file = recordPath(cwd, 'review');
        return { records, file, cwd };
    }
}
const latestByReviewId = (dedupeById);
function formatRecord(record) {
    return [record.createdAt, record.id, record.status, record.requester, record.reviewer ?? '-', record.summary]
        .filter(Boolean)
        .join('  ');
}
//# sourceMappingURL=list.js.map