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

async function checkZMs() {
    try {
        const users = await db.User.findAll({
            include: [
                {
                    model: db.UserRole,
                    as: 'userRoles',
                    where: { isActive: true },
                    include: [{ model: db.Role, as: 'role' }]
                }
            ]
        });

        console.log('--- Active Zonal Manager Roles ---');
        users.forEach((u: any) => {
            const zms = (u.userRoles || []).filter((ur: any) => ['ZM', 'DD-ZM', 'ZBH'].includes(ur.role?.roleCode));
            if (zms.length > 0) {
                console.log(`User: ${u.fullName} (ID: ${u.id}, EmployeeID: ${u.employeeId})`);
                zms.forEach((zm: any) => {
                    console.log(`  Role: ${zm.role.roleCode}, managerCode: ${zm.managerCode}, isActive: ${zm.isActive}`);
                });
            }
        });
        process.exit(0);
    } catch (err) {
        console.error('Error checking ZMs:', err);
        process.exit(1);
    }
}

checkZMs();
