-- ============================================================================
-- Restore Operations Department Menu
-- ============================================================================
-- Purpose: Restore Operations menu that was lost during migration cleanup
-- Date: 2026-02-04
-- ============================================================================

-- Remove any incorrect/duplicate Operations entries
DELETE FROM menu_items WHERE label = 'Operations' AND parent_id NOT IN (2);

-- Insert Operations parent menu under DEPARTMENTS (parent_id = 2)
INSERT INTO menu_items (label, url, icon, parent_id, display_order, controller, action, http_method, permission_required, is_active, created_at)
VALUES ('Operations', '#', 'fas fa-cogs', 2, 93, NULL, NULL, 'GET', 'operations.view', 1, NOW())
ON DUPLICATE KEY UPDATE label = VALUES(label), icon = VALUES(icon);

-- Get the Operations menu ID
SET @operations_menu_id = (SELECT id FROM menu_items WHERE label = 'Operations' AND parent_id = 2 LIMIT 1);

-- Insert/Update child menu items
INSERT INTO menu_items (label, url, parent_id, display_order, controller, action, http_method, permission_required, is_active, created_at) VALUES
('Dashboard', 'operations', @operations_menu_id, 1, 'OperationsController', 'index', 'GET', 'operations.view', 1, NOW()),
('Assignments', 'operations/assignments', @operations_menu_id, 2, 'OperationsEquipmentController', 'assignments', 'GET', 'operations.view', 1, NOW()),
('Equipment Registry', 'operations/equipment', @operations_menu_id, 3, 'OperationsEquipmentController', 'index', 'GET', 'operations.view', 1, NOW()),
('Maintenance Schedule', 'operations/maintenance', @operations_menu_id, 4, 'OperationsMaintenanceController', 'index', 'GET', 'operations.maintenance.view', 1, NOW()),
('Research', 'operations/research', @operations_menu_id, 5, 'OperationsResearchController', 'index', 'GET', 'operations.research.view', 1, NOW()),
('Software Licenses', 'operations/licenses', @operations_menu_id, 6, 'OperationsLicensesController', 'index', 'GET', 'operations.licenses.view', 1, NOW())
ON DUPLICATE KEY UPDATE 
    label = VALUES(label),
    display_order = VALUES(display_order),
    controller = VALUES(controller),
    action = VALUES(action);

-- Verify results
SELECT 'Operations menu restored successfully!' as status;
SELECT id, label, url, display_order 
FROM menu_items 
WHERE id = @operations_menu_id OR parent_id = @operations_menu_id
ORDER BY display_order;
