'use strict';

/**
 * Contract: payload diff
 *
 * Tampilkan perbedaan kolom antara payload JSON dan tabel database (read-only).
 *
 * Inline migration v4.0.0: business logic dipindah ke
 * generators/lib/payload/payload-runner.js (dari create-payload.js).
 * Handler instantiate PayloadGenerator dan inject mode diff=true.
 */

const { PayloadGenerator } = require('../../lib/payload/payload-runner');

module.exports = {
    resource: 'payload',
    verb: 'diff',
    description: 'Tampilkan perbedaan kolom antara payload JSON dan tabel database (read-only)',
    category: 'introspection',
    flags: {
        config: {
            type: 'string',
            required: false,
            default: null,
            description: 'File config database (.env). Fallback ke `.restforge/defaults.json` bila tidak disediakan eksplisit (set via `config set-default`)'
        },
        table: {
            type: 'string',
            required: false,
            default: null,
            description: 'Diff hanya satu tabel spesifik (default: semua)'
        }
    },
    examples: [
        'npx restforge payload diff --config=db.env',
        'npx restforge payload diff --config=db.env --table=orders'
    ],
    async handler(args) {
        const generator = new PayloadGenerator();
        await generator.run({
            config: args.config,
            table: args.table || null,
            diff: true
        });
    }
};
