-- ============================================================
-- NICC Admin Menu - Migracion 0010
-- Agregar plugin SIE Deployer (siedeployer)
-- ============================================================

INSERT OR IGNORE INTO admin_menu_items (
    category_id,
    code,
    plugin_name,
    name,
    description,
    icon,
    url,
    sort_order,
    is_active,
    is_dangerous,
    requires_confirmation
)
SELECT
    (SELECT id FROM admin_menu_categories WHERE code IN ('danger', 'tools') ORDER BY
        CASE code
            WHEN 'danger' THEN 1
            WHEN 'tools' THEN 2
            ELSE 3
        END
    LIMIT 1),
    'siedeployer',
    'siedeployer',
    'SIE Deployer',
    'Crear y provisionar nuevos sistemas SIE - SOLO SUPERUSUARIO',
    'server',
    '?do=admin&page=siedeployer',
    99,
    1,
    1,
    1
WHERE NOT EXISTS (SELECT 1 FROM admin_menu_items WHERE code = 'siedeployer');

-- Solo superusuario (herramienta critica)
INSERT OR REPLACE INTO admin_menu_permissions (item_id, role, can_view, can_execute)
SELECT id, 'superuser', 1, 1 FROM admin_menu_items WHERE code = 'siedeployer';

-- Denegar a admin y manager
INSERT OR REPLACE INTO admin_menu_permissions (item_id, role, can_view, can_execute)
SELECT id, 'admin', 0, 0 FROM admin_menu_items WHERE code = 'siedeployer';

INSERT OR REPLACE INTO admin_menu_permissions (item_id, role, can_view, can_execute)
SELECT id, 'manager', 0, 0 FROM admin_menu_items WHERE code = 'siedeployer';

-- Fin de migracion
SELECT 1;
