-- =========================================================
-- 045_spk_monitor_permissions.sql
-- Sprint 17: SPK monitor + terminal permissions
-- =========================================================

INSERT IGNORE INTO permissions (code, name, module, created_at) VALUES
('spk.monitor.view','Lihat Monitor Produksi SPK','spk',NOW()),
('spk.monitor.manage','Kelola Monitor Produksi SPK','spk',NOW()),
('spk.terminals.manage','Kelola Akun Terminal SPK','spk',NOW());

INSERT IGNORE INTO role_permissions (role_id, permission_id)
SELECT r.id, p.id
FROM roles r
JOIN permissions p ON p.code IN (
  'spk.monitor.view',
  'spk.monitor.manage',
  'spk.terminals.manage'
)
WHERE r.code IN ('owner','admin','kepala_toko');
