"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleApiCopyCommand = void 0;
const services_1 = require("../../api/services");
const ui_1 = require("../../utils/ui");
const prompt_1 = require("../../utils/prompt");
const shared_1 = require("./shared");
async function handleApiCopyCommand(args) {
    await (0, ui_1.initUI)();
    const parsedArgs = (0, shared_1.parseApiCommandArgs)(args, { maxPositionals: 2 });
    (0, shared_1.exitOnApiCommandErrors)(parsedArgs.errors);
    const source = parsedArgs.positionals[0];
    let destination = parsedArgs.positionals[1];
    if (!source) {
        console.log((0, ui_1.fail)('Source profile is required. Usage: ccs api copy <source> <destination>'));
        process.exit(1);
    }
    if (!destination) {
        destination = await prompt_1.InteractivePrompt.input('Destination profile name');
    }
    if (!parsedArgs.yes) {
        const confirmed = await prompt_1.InteractivePrompt.confirm(`Copy profile "${source}" to "${destination}"?`, { default: true });
        if (!confirmed) {
            console.log((0, ui_1.info)('Cancelled'));
            process.exit(0);
        }
    }
    const result = (0, services_1.copyApiProfile)(source, destination, {
        target: parsedArgs.target,
        force: parsedArgs.force,
    });
    if (!result.success) {
        console.log((0, ui_1.fail)(result.error || 'Failed to copy profile'));
        process.exit(1);
    }
    console.log((0, ui_1.ok)(`Profile copied: ${source} -> ${destination}`));
    result.warnings?.forEach((warningMessage) => console.log((0, ui_1.warn)(warningMessage)));
    console.log('');
}
exports.handleApiCopyCommand = handleApiCopyCommand;
//# sourceMappingURL=copy-command.js.map