/*
 * 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 { deleteTask, getTask, taskStatePath } from '../../../services/task-state.js';
import { resolveTaskId, taskIdentifierFlags } from '../../../util/task-flags.js';
import { resolveWorkspaceRoot } from '../../../services/workspace-root.js';
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@jterrats/setup-agents', 'setup-agents.task.delete');
export default class TaskDelete extends SfCommand {
    static summary = messages.getMessage('summary');
    static description = messages.getMessage('description');
    static examples = messages.getMessages('examples');
    static flags = {
        ...taskIdentifierFlags,
        yes: Flags.boolean({
            char: 'y',
            summary: messages.getMessage('flags.yes.summary'),
            description: messages.getMessage('flags.yes.description'),
            default: false,
        }),
    };
    async run() {
        const { flags } = await this.parse(TaskDelete);
        const cwd = resolveWorkspaceRoot(flags);
        const file = taskStatePath(cwd);
        const taskId = resolveTaskId(flags);
        if (!getTask(cwd, taskId))
            throw new Error(messages.getMessage('errors.notFound', [taskId]));
        if (!flags.yes) {
            const confirmed = await this.confirm({ message: `Delete task ${taskId}? This cannot be undone.` });
            if (!confirmed) {
                this.log('Aborted.');
                return { record: getTask(cwd, taskId), file, cwd };
            }
        }
        const record = deleteTask(cwd, taskId);
        this.log(messages.getMessage('info.deleted', [record.id]));
        return { record, file, cwd };
    }
}
//# sourceMappingURL=delete.js.map