/*
 * 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 { readFileSync } from 'node:fs';
import { Messages } from '@salesforce/core';
import { Flags, SfCommand } from '@salesforce/sf-plugins-core';
import { importWorkspace } from '../../services/export-import.js';
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@jterrats/setup-agents', 'setup-agents.import');
const CONFLICT_OPTIONS = ['skip', 'overwrite'];
export default class Import extends SfCommand {
    static summary = messages.getMessage('summary');
    static description = messages.getMessage('description');
    static examples = messages.getMessages('examples');
    static flags = {
        file: Flags.string({
            summary: messages.getMessage('flags.file.summary'),
            description: messages.getMessage('flags.file.description'),
            required: true,
        }),
        'on-conflict': Flags.string({
            summary: messages.getMessage('flags.on-conflict.summary'),
            description: messages.getMessage('flags.on-conflict.description'),
            options: [...CONFLICT_OPTIONS],
            default: 'skip',
        }),
        'dry-run': Flags.boolean({
            summary: messages.getMessage('flags.dry-run.summary'),
            description: messages.getMessage('flags.dry-run.description'),
            default: false,
        }),
    };
    async run() {
        const { flags } = await this.parse(Import);
        const cwd = process.cwd();
        const rawContent = readFileSync(flags.file, 'utf8');
        const bundle = JSON.parse(rawContent);
        const result = importWorkspace(cwd, bundle, {
            onConflict: flags['on-conflict'],
            dryRun: flags['dry-run'],
        });
        if (result.dryRun) {
            const { tasks, decisions, evidence, handoffs, reviews } = result.imported;
            this.log(messages.getMessage('info.dry-run', [
                String(tasks),
                String(decisions),
                String(evidence),
                String(handoffs),
                String(reviews),
            ]));
        }
        else {
            const i = result.imported;
            const s = result.skipped;
            this.log(messages.getMessage('info.result', [
                String(i.tasks),
                String(i.decisions),
                String(i.evidence),
                String(i.handoffs),
                String(i.reviews),
                String(s.tasks),
                String(s.decisions),
                String(s.evidence),
                String(s.handoffs),
                String(s.reviews),
            ]));
        }
        return result;
    }
}
//# sourceMappingURL=import.js.map