'use strict';

/**
 * Contract: payload validate
 *
 * Validate payload terhadap struktur 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 validate=true.
 */

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

module.exports = {
    resource: 'payload',
    verb: 'validate',
    description: 'Validate payload terhadap struktur 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: 'Validate hanya satu tabel spesifik (default: semua)'
        }
    },
    examples: [
        'npx restforge payload validate --config=db.env',
        'npx restforge payload validate --config=db.env --table=users'
    ],
    async handler(args) {
        const generator = new PayloadGenerator();
        await generator.run({
            config: args.config,
            table: args.table || null,
            validate: true
        });
    }
};
