import { BaseCommand } from '@adonisjs/core/ace';
export default class FixDates extends BaseCommand {
    static commandName = 'fix:dates';
    static description = 'Fix invalid ISO dates in SQLite database';
    static options = {
        startApp: true,
    };
    async run() {
        const { default: db } = await import('@adonisjs/lucid/services/db');
        const { DateTime } = await import('luxon');
        const tables = [
            'projects', 'categories', 'tags', 'trainings',
            'experiences', 'music', 'information', 'images', 'users'
        ];
        this.logger.info('Starting to fix dates in the database...');
        let totalFixed = 0;
        for (const table of tables) {
            try {
                const rows = await db.from(table).select('*');
                let tableFixed = 0;
                for (const row of rows) {
                    const updates = {};
                    for (const [key, value] of Object.entries(row)) {
                        if (typeof value === 'string' && value.includes('T')) {
                            const parsed = DateTime.fromISO(value);
                            if (parsed.isValid) {
                                updates[key] = parsed.toFormat('yyyy-MM-dd HH:mm:ss');
                            }
                        }
                    }
                    if (Object.keys(updates).length > 0) {
                        await db.from(table).where('id', row.id).update(updates);
                        tableFixed++;
                        totalFixed++;
                    }
                }
                if (tableFixed > 0) {
                    this.logger.success(`Fixed ${tableFixed} rows in table "${table}"`);
                }
                else {
                    this.logger.info(`No invalid dates found in table "${table}"`);
                }
            }
            catch (error) {
                this.logger.warning(`Failed to process table "${table}": ${error.message}`);
            }
        }
        this.logger.success(`Date fixing complete! Total rows fixed: ${totalFixed}`);
    }
}
//# sourceMappingURL=fix_dates.js.map