-- Agregar permiso 'maintenance' a los roles existentes
-- Ejecutar en phpMyAdmin después de 002_maintenance_module.sql

-- Superadmin y Admin: acceso total
UPDATE roles
SET permissions = JSON_SET(permissions, '$.maintenance', JSON_OBJECT(
    'view', true, 'create', true, 'edit', true, 'delete', true
))
WHERE level >= 80;

-- Supervisor: ver, crear, editar
UPDATE roles
SET permissions = JSON_SET(permissions, '$.maintenance', JSON_OBJECT(
    'view', true, 'create', true, 'edit', true, 'delete', false
))
WHERE level >= 40 AND level < 80;

-- Usuario básico: solo ver
UPDATE roles
SET permissions = JSON_SET(permissions, '$.maintenance', JSON_OBJECT(
    'view', true, 'create', false, 'edit', false, 'delete', false
))
WHERE level < 40;

-- Verificar
SELECT id, label, level,
       JSON_EXTRACT(permissions, '$.maintenance') AS maintenance_perms
FROM roles ORDER BY level DESC;
