-- MAY SAFE BOX: module access and report access permissions
-- Safe to import more than once (unique records are ignored).
-- No table or column changes are made by this script.

START TRANSACTION;

INSERT IGNORE INTO `permissions` (`name`, `guard_name`, `created_at`, `updated_at`) VALUES
('access_dashboard', 'web', NOW(), NOW()),
('access_customers', 'web', NOW(), NOW()),
('access_safe_boxes', 'web', NOW(), NOW()),
('access_appointments', 'web', NOW(), NOW()),
('access_payments', 'web', NOW(), NOW()),
('access_reminders', 'web', NOW(), NOW()),
('access_holidays', 'web', NOW(), NOW()),
('access_logs', 'web', NOW(), NOW()),
('access_audit_logs', 'web', NOW(), NOW()),
('report_lockers', 'web', NOW(), NOW()),
('report_locker_expiry', 'web', NOW(), NOW()),
('report_appointments', 'web', NOW(), NOW()),
('report_reminders', 'web', NOW(), NOW()),
('report_payments', 'web', NOW(), NOW()),
('report_referrals', 'web', NOW(), NOW()),
('report_locker_updates', 'web', NOW(), NOW()),
('report_locker_changes', 'web', NOW(), NOW()),
('report_blocked_lockers', 'web', NOW(), NOW());

INSERT IGNORE INTO `roles` (`name`, `guard_name`, `created_at`, `updated_at`) VALUES
('Super Admin', 'web', NOW(), NOW()),
('User', 'web', NOW(), NOW());

-- Super Admin receives every permission defined above.
INSERT IGNORE INTO `role_has_permissions` (`permission_id`, `role_id`)
SELECT p.id, r.id
FROM `permissions` p
INNER JOIN `roles` r ON r.name = 'Super Admin' AND r.guard_name = 'web'
WHERE p.guard_name = 'web'
  AND p.name IN (
    'access_dashboard',
    'access_customers',
    'access_safe_boxes',
    'access_appointments',
    'access_payments',
    'access_reminders',
    'access_holidays',
    'access_logs',
    'access_audit_logs',
    'report_lockers',
    'report_locker_expiry',
    'report_appointments',
    'report_reminders',
    'report_payments',
    'report_referrals',
    'report_locker_updates',
    'report_locker_changes',
    'report_blocked_lockers'
  );

COMMIT;

-- After importing, run this once in the application directory:
-- php artisan permission:cache-reset
