-- 幸运礼物 AB 实验管理是独立按钮权限：创建/调量/白名单/结束实验都会发布或钉住规则版本，
-- 权限边界与 lucky-gift:update 一致（platform-admin、ops-admin、product-lead），查看仍复用 lucky-gift:view。
SET @now_ms = CAST(UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000 AS UNSIGNED);

INSERT INTO admin_permissions (name, code, kind, description, created_at_ms, updated_at_ms) VALUES
  ('幸运礼物实验管理', 'lucky-gift:experiment', 'button', '允许创建、放量、暂停、白名单和结束幸运礼物 AB 实验', @now_ms, @now_ms)
ON DUPLICATE KEY UPDATE
  name = VALUES(name),
  kind = VALUES(kind),
  description = VALUES(description),
  updated_at_ms = @now_ms;

INSERT IGNORE INTO admin_role_permissions (role_id, permission_id)
SELECT role.id, permission.id
FROM admin_roles role
JOIN admin_permissions permission
WHERE role.code IN ('platform-admin', 'ops-admin', 'product-lead')
  AND permission.code = 'lucky-gift:experiment';
