import db from '../src/database/models/index.js';

async function fixEnum() {
    const enumName = 'enum_constitutional_changes_changeType';
    const newValues = ['Proprietorship', 'Partnership', 'LLP', 'Private Limited'];

    console.log(`--- Patching DB ENUM: ${enumName} ---`);

    for (const val of newValues) {
        try {
            // Sequelize does not have a direct method for ADD VALUE to ENUM in all dialects, using raw query
            // Using check to avoid "already exists" error
            await db.sequelize.query(`ALTER TYPE "${enumName}" ADD VALUE IF NOT EXISTS '${val}'`);
            console.log(`✅ Added '${val}' to ${enumName}`);
        } catch (err: any) {
            if (err.message.includes('already exists')) {
                console.log(`ℹ️ '${val}' already exists in ${enumName}`);
            } else {
                console.log(`❌ Failed to add '${val}':`, err.message);
            }
        }
    }

    console.log('--- ENUM Patching Complete ---');
}

fixEnum().catch(err => {
    console.error('Migration failed:', err);
    process.exit(1);
}).then(() => process.exit(0));
