-- =========================================================
-- 031_spk_permissions.sql
-- Sprint 12: SPK permissions seed
-- =========================================================

INSERT IGNORE INTO permissions (code, name, module, created_at) VALUES
('spk.view','Lihat SPK Produksi','spk',NOW()),
('spk.create','Buat SPK Produksi','spk',NOW()),
('spk.edit','Edit SPK Produksi','spk',NOW()),
('spk.print','Cetak SPK Produksi','spk',NOW()),
('spk.scan','Akses Landing SPK','spk',NOW()),
('spk.manage_departments','Kelola Departemen Produksi 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.view',
  'spk.create',
  'spk.edit',
  'spk.print',
  'spk.scan',
  'spk.manage_departments'
)
WHERE r.code IN ('owner','admin','kepala_toko');
