
import 'dotenv/config';
import { Sequelize } from 'sequelize';

const sequelize = new Sequelize('royal_enfield_onboarding', 'laxman', '<.efvP1D0^80Z)r5', {
    host: 'localhost',
    dialect: 'postgres',
    logging: console.log
});

const run = async () => {
    try {
        await sequelize.authenticate();
        console.log('Connected to database.');

        const stagesToAdd = [
            'Level 1 Approved',
            'Level 2 Approved',
            'Level 2 Recommended',
            'Level 3 Approved'
        ];

        for (const stage of stagesToAdd) {
            try {
                await sequelize.query(`ALTER TYPE "enum_applications_currentStage" ADD VALUE IF NOT EXISTS '${stage}';`);
                console.log(`Added '${stage}' to enum_applications_currentStage`);
            } catch (e: any) {
                console.log(`'${stage}' might already exist in enum_applications_currentStage or error:`, e.message);
            }

            try {
                await sequelize.query(`ALTER TYPE "enum_applications_overallStatus" ADD VALUE IF NOT EXISTS '${stage}';`);
                console.log(`Added '${stage}' to enum_applications_overallStatus`);
            } catch (e: any) {
                console.log(`'${stage}' might already exist in enum_applications_overallStatus or error:`, e.message);
            }
        }

        console.log('Successfully updated enums.');
        process.exit(0);
    } catch (error) {
        console.error('Error:', error);
        process.exit(1);
    }
};

run();
