'use strict';

/**
 * Contract: config schema
 *
 * Output JSON schema dari parameter db-connection.env (introspection untuk
 * AI agent / MCP server / documentation auto-generation).
 *
 * Inline migration v4.0.0: business logic asli dari config-schema.js
 * di-inline langsung di handler. Adapter process.argv override dihapus karena
 * handler langsung pakai args.pretty.
 */

const {
    DB_CONNECTION_ENV_TEMPLATE,
    parseTemplateAsSchema
} = require('../../lib/templates/db-connection-env');

module.exports = {
    resource: 'config',
    verb: 'schema',
    description: 'Output JSON schema dari parameter db-connection.env',
    category: 'introspection',
    flags: {
        pretty: {
            type: 'boolean',
            required: false,
            default: true,
            description: 'Pretty-print output JSON'
        }
    },
    examples: [
        'npx restforge config schema',
        'npx restforge config schema --pretty=false'
    ],
    async handler(args) {
        const pretty = args.pretty !== false;
        const parameters = parseTemplateAsSchema(DB_CONNECTION_ENV_TEMPLATE);

        const output = {
            schemaVersion: '1.0',
            sourceTemplate: 'db-connection.env',
            totalCount: parameters.length,
            parameters
        };

        const json = pretty
            ? JSON.stringify(output, null, 2)
            : JSON.stringify(output);

        console.log(json);
    }
};
