'use strict';

/**
 * Contract: config clear-default
 *
 * Menghapus default config untuk working directory saat ini. Hanya menghapus
 * file .restforge/defaults.json, tidak menghapus file config aktual (.env).
 *
 * Inline migration v4.0.0: business logic asli dari config-clear-default.js
 * di-inline langsung di handler. Adapter process.argv override dihapus karena
 * handler tidak butuh argv. process.exit() di legacy dikonversi menjadi return
 * (success) atau throw (error).
 */

const {
    clearDefaultConfig,
    getDefaultsFilePath
} = require('../../lib/utils/config-resolver');

module.exports = {
    resource: 'config',
    verb: 'clear-default',
    description: 'Menghapus default config untuk working directory saat ini',
    category: 'management',
    flags: {},
    examples: [
        'npx restforge config clear-default'
    ],
    async handler(_args) {
        const cwd = process.cwd();
        const result = clearDefaultConfig(cwd);

        if (!result.removed) {
            console.log('');
            console.log('No default config to clear (file does not exist).');
            console.log('');
            console.log(`  Looked at: ${getDefaultsFilePath(cwd)}`);
            console.log('');
            return;
        }

        console.log('');
        console.log('Default config cleared successfully.');
        console.log('');
        console.log(`  Removed: ${result.filePath}`);
        console.log('');
        console.log('Commands accepting --config now require it explicitly.');
        console.log('');
    }
};
