-- Insert Tasks menu if it doesn't exist
INSERT INTO menus (name, title, icon, path, component, parent_id, sort_order, is_active)
SELECT 'system_tasks', 'System Tasks', 'schedule', '/admin/tasks', 'admin/Tasks', m.id, 30, true
FROM menus m
WHERE m.name = 'platform_management'
AND NOT EXISTS (SELECT 1 FROM menus WHERE name = 'system_tasks' AND parent_id = m.id);

-- Assign to admin role
INSERT INTO role_menus (role_id, menu_id, created_at)
SELECT r.id, m.id, NOW()
FROM roles r, menus m
WHERE r.name = 'admin' AND m.name = 'system_tasks'
AND NOT EXISTS (SELECT 1 FROM role_menus rm WHERE rm.role_id = r.id AND rm.menu_id = m.id);
