-- ============================================================
-- NICC Admin Menu - Migracion 0008
-- Agregar plugin Gestor de Fechas de Comentarios (commentdates)
-- ============================================================

-- Agregar el item commentdates a la categoria de herramientas
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 ('tools', 'nicc_modules') ORDER BY
        CASE code
            WHEN 'tools' THEN 1
            WHEN 'nicc_modules' THEN 2
            ELSE 3
        END
    LIMIT 1),
    'commentdates',
    'commentdates',
    'Gestor de Fechas',
    'Modifica fechas de creacion de comentarios y proyectos BEZ',
    'clock',
    '?do=admin&page=commentdates',
    96,
    1,
    0,
    1
WHERE NOT EXISTS (SELECT 1 FROM admin_menu_items WHERE code = 'commentdates');

-- Permisos para manager (acceso total - herramienta operativa)
INSERT OR REPLACE INTO admin_menu_permissions (item_id, role, can_view, can_execute)
SELECT id, 'manager', 1, 1 FROM admin_menu_items WHERE code = 'commentdates';

-- Permisos para admin (acceso total)
INSERT OR REPLACE INTO admin_menu_permissions (item_id, role, can_view, can_execute)
SELECT id, 'admin', 1, 1 FROM admin_menu_items WHERE code = 'commentdates';

-- Permisos para superuser
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 = 'commentdates';

-- Fin de migracion
SELECT 1;
