-- =========================================================
-- 034_monthly_loans_permissions.sql
-- Sprint 13: Peminjaman Bulanan permissions seed
-- =========================================================

INSERT IGNORE INTO permissions (code, name, module, created_at) VALUES
('loan.view','Lihat Peminjaman Bulanan','loan',NOW()),
('loan.manage','Kelola Peminjaman Bulanan','loan',NOW()),
('loan.close','Tutup Buku Peminjaman Bulanan','loan',NOW()),
('loan.print','Cetak Peminjaman Bulanan','loan',NOW()),
('loan.scan','Akses Landing QR Peminjaman Bulanan','loan',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 (
  'loan.view',
  'loan.manage',
  'loan.close',
  'loan.print',
  'loan.scan'
)
WHERE r.code IN ('owner','admin','kepala_toko');
