
import db from './src/database/models/index.js';
import { WorkflowService } from './src/services/WorkflowService.js';
import { APPLICATION_STATUS } from './src/common/config/constants.js';

async function heal() {
  try {
    const applicationId = 'f2f55d38-befc-4d9a-b216-4e39fb2fb30e';
    const application = await db.Application.findByPk(applicationId);
    
    console.log(`Healing application ${application.applicationId}...`);
    
    const request = await db.LoaRequest.findOne({ where: { applicationId: application.id } });
    if (request) {
        await request.update({ status: 'Approved', approvedAt: new Date() });
    }
    
    await WorkflowService.transitionApplication(application, APPLICATION_STATUS.EOR_IN_PROGRESS, '18122cf4-d905-484c-a9ff-7b6229f101ef', {
        reason: 'Manually recovered: LOA Policy met with required DD Head & NBH approvals.',
        progressPercentage: 97
    });
    
    console.log('Done.');
    process.exit(0);
  } catch (e) {
    console.error(e);
    process.exit(1);
  }
}
heal();
