/*
 * 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 { listTasks, taskStatePath } from '../../../services/task-state.js';
import { resolveWorkspaceRoot } from '../../../services/workspace-root.js';
import { workspaceFlags } from '../../../util/task-flags.js';
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@jterrats/setup-agents', 'setup-agents.task.list');
const TASK_STATUSES = ['open', 'claimed', 'done'];
const WORKSPACE_MODES = ['project', 'advisory'];
export default class TaskList extends SfCommand {
    static summary = messages.getMessage('summary');
    static description = messages.getMessage('description');
    static examples = messages.getMessages('examples');
    static flags = {
        ...workspaceFlags,
        status: Flags.string({
            summary: messages.getMessage('flags.status.summary'),
            description: messages.getMessage('flags.status.description'),
            options: [...TASK_STATUSES],
        }),
        role: Flags.string({
            char: 'r',
            summary: messages.getMessage('flags.role.summary'),
            description: messages.getMessage('flags.role.description'),
        }),
        profile: Flags.string({
            char: 'p',
            summary: messages.getMessage('flags.profile.summary'),
            description: messages.getMessage('flags.profile.description'),
        }),
        mode: Flags.string({
            summary: messages.getMessage('flags.mode.summary'),
            description: messages.getMessage('flags.mode.description'),
            options: [...WORKSPACE_MODES],
        }),
        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(TaskList);
        const cwd = resolveWorkspaceRoot(flags);
        const file = taskStatePath(cwd);
        const records = listTasks(cwd, {
            status: flags.status,
            profile: flags.profile ?? flags.role,
            mode: flags.mode,
            limit: flags.limit,
        });
        if (records.length === 0) {
            this.log(messages.getMessage('info.empty'));
        }
        else {
            for (const record of records)
                this.log(formatRecord(record));
        }
        return { records, file, cwd };
    }
}
function formatRecord(record) {
    return [
        record.updatedAt,
        record.id,
        record.status,
        record.owner ?? '',
        record.evidenceIds.join(',') || '-',
        record.summary,
    ]
        .filter(Boolean)
        .join('  ');
}
//# sourceMappingURL=list.js.map