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

async function repairPolicy() {
    console.log('--- Repairing FDD_VERIFICATION Policy ---');
    
    // Update FDD_VERIFICATION to allow Finance and DD Admin
    const [policy] = await db.StageApprovalPolicy.findOrCreate({
        where: { stageCode: 'FDD_VERIFICATION' },
        defaults: {
            stageCode: 'FDD_VERIFICATION',
            minApprovals: 1,
            approvalMode: 'ROLE_MANDATORY',
            requiredRoles: ['FDD', 'Finance', 'DD Admin', 'Finance Admin'],
            isActive: true
        }
    });

    if (policy) {
        await policy.update({
            requiredRoles: ['FDD', 'Finance', 'DD Admin', 'Finance Admin', 'DD Head'],
            minApprovals: 1
        });
        console.log('Policy updated successfully:', policy.requiredRoles);
    }
}

repairPolicy().catch(console.error).then(() => process.exit(0));
