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

const addRecoveryEnum = async () => {
    try {
        console.log('>>> STARTING ENUM UPDATE: FnFLineItem itemType <<<');
        await db.sequelize.authenticate();
        console.log('Database connection established.');

        // Raw query to add 'Recovery' to the itemType enum
        try {
            await db.sequelize.query(`ALTER TYPE "enum_fnf_line_items_itemType" ADD VALUE IF NOT EXISTS 'Recovery';`);
            console.log('SUCCESS: Added "Recovery" to "enum_fnf_line_items_itemType"');
        } catch (e) {
            console.log('NOTICE: "Recovery" likely already exists or another error occurred:', e.message);
        }

        await db.sequelize.close();
        console.log('>>> ENUM UPDATE COMPLETED <<<');
        process.exit(0);
    } catch (error) {
        console.error('>>> ERROR: Failed to update Enum:', error);
        process.exit(1);
    }
};

addRecoveryEnum();
