-- IoT v2.0 新功能菜单
-- 说明：不写死 ID，parent_id 通过子查询按名称取，避免不同环境 ID 不一致
-- 注意：告警记录 v2 (iot/alarm/record/list) 待补 IotAlarmRecordController 后再加

-- ─────────────────────────────────────────────
-- 1. 规则链管理（父: 规则引擎）
-- ─────────────────────────────────────────────
INSERT INTO `system_menu` (`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`)
VALUES ('规则链管理', '', 2, 3,
  (SELECT id FROM (SELECT id FROM system_menu WHERE name = '规则引擎' AND deleted = b'0' LIMIT 1) t),
  'rule-chain', 'fa-solid:project-diagram', 'iot/rule/chain/list', 'RuleChainList',
  0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0');

-- 规则链管理 按钮
INSERT INTO `system_menu` (`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`)
VALUES
  ('规则链查询',     'iot:rule:query',  3, 1, (SELECT id FROM (SELECT id FROM system_menu WHERE name = '规则链管理' AND deleted = b'0' LIMIT 1) t), '', '', '', NULL, 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'),
  ('规则链创建',     'iot:rule:create', 3, 2, (SELECT id FROM (SELECT id FROM system_menu WHERE name = '规则链管理' AND deleted = b'0' LIMIT 1) t), '', '', '', NULL, 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'),
  ('规则链更新',     'iot:rule:update', 3, 3, (SELECT id FROM (SELECT id FROM system_menu WHERE name = '规则链管理' AND deleted = b'0' LIMIT 1) t), '', '', '', NULL, 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'),
  ('规则链删除',     'iot:rule:delete', 3, 4, (SELECT id FROM (SELECT id FROM system_menu WHERE name = '规则链管理' AND deleted = b'0' LIMIT 1) t), '', '', '', NULL, 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'),
  ('规则链启用停用', 'iot:rule:update', 3, 5, (SELECT id FROM (SELECT id FROM system_menu WHERE name = '规则链管理' AND deleted = b'0' LIMIT 1) t), '', '', '', NULL, 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0');

-- 规则链编辑器（隐藏路由，供列表页 router.push 跳转）
INSERT INTO `system_menu` (`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`)
VALUES ('规则链编辑器', '', 2, 99,
  (SELECT id FROM (SELECT id FROM system_menu WHERE name = '规则引擎' AND deleted = b'0' LIMIT 1) t),
  'rule-chain/edit/:id?', '', 'iot/rule/chain/edit', 'RuleChainEdit',
  0, b'0', b'0', b'0', '1', NOW(), '1', NOW(), b'0');

-- ─────────────────────────────────────────────
-- 2. 子系统管理（父: 设备接入）
-- ─────────────────────────────────────────────
INSERT INTO `system_menu` (`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`)
VALUES ('子系统管理', '', 2, 4,
  (SELECT id FROM (SELECT id FROM system_menu WHERE name = '设备接入' AND deleted = b'0' LIMIT 1) t),
  'subsystem', 'fa-solid:layer-group', 'iot/subsystem/list', 'IoTSubsystemList',
  0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0');

-- 子系统管理 按钮
INSERT INTO `system_menu` (`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`)
VALUES
  ('子系统查询', 'iot:subsystem:query',  3, 1, (SELECT id FROM (SELECT id FROM system_menu WHERE name = '子系统管理' AND deleted = b'0' LIMIT 1) t), '', '', '', NULL, 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'),
  ('子系统创建', 'iot:subsystem:create', 3, 2, (SELECT id FROM (SELECT id FROM system_menu WHERE name = '子系统管理' AND deleted = b'0' LIMIT 1) t), '', '', '', NULL, 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'),
  ('子系统更新', 'iot:subsystem:update', 3, 3, (SELECT id FROM (SELECT id FROM system_menu WHERE name = '子系统管理' AND deleted = b'0' LIMIT 1) t), '', '', '', NULL, 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0'),
  ('子系统删除', 'iot:subsystem:delete', 3, 4, (SELECT id FROM (SELECT id FROM system_menu WHERE name = '子系统管理' AND deleted = b'0' LIMIT 1) t), '', '', '', NULL, 0, b'1', b'1', b'1', '1', NOW(), '1', NOW(), b'0');

-- ─────────────────────────────────────────────
-- TODO: 告警记录 v2（待补 IotAlarmRecordController）
-- ─────────────────────────────────────────────
-- 前端: iot/alarm/record/list (IoTAlarmRecordList)
-- 接口: /iot/alarm-record/* — 需先创建后端 Controller
-- 父菜单: 告警中心 (sort=3)
-- 按钮权限: iot:alarm-record:query / ack / clear / archive
