import 'dotenv/config';
import db from '../src/database/models/index.js';
import { SLA_STAGE_CATALOG } from '../src/common/config/slaStageCatalog.js';
import { seedSlaCatalogEntries } from '../src/common/utils/slaSeedUtils.js';

async function seedSlaConfigs() {
    const { sequelize } = db as any;
    await sequelize.authenticate();
    console.log('Database connected.');

    const transaction = await sequelize.transaction();
    try {
        await seedSlaCatalogEntries(db, SLA_STAGE_CATALOG, transaction);
        await transaction.commit();
        console.log(
            `SLA configurations seeded successfully. Total activities: ${SLA_STAGE_CATALOG.length}`
        );
    } catch (error) {
        await transaction.rollback();
        console.error('SLA seed failed:', error);
        throw error;
    } finally {
        await sequelize.close();
    }
}

seedSlaConfigs().catch((err) => {
    console.error(err);
    process.exit(1);
});
