USE samity360;

-- Company-specific Notification page and send permissions.
-- Existing companies keep Admin/Manager access by default, while Collector
-- and Accountant remain disabled until the Developer enables them.
INSERT IGNORE INTO company_role_permissions
    (company_id, role_slug, permission_slug, allowed, updated_by)
SELECT c.id, defaults.role_slug, defaults.permission_slug, defaults.allowed, NULL
FROM companies c
CROSS JOIN (
    SELECT 'admin' role_slug, 'notifications.view' permission_slug, 1 allowed
    UNION ALL SELECT 'admin', 'notifications.send', 1
    UNION ALL SELECT 'manager', 'notifications.view', 1
    UNION ALL SELECT 'manager', 'notifications.send', 1
    UNION ALL SELECT 'collector', 'notifications.view', 0
    UNION ALL SELECT 'collector', 'notifications.send', 0
    UNION ALL SELECT 'accountant', 'notifications.view', 0
    UNION ALL SELECT 'accountant', 'notifications.send', 0
) defaults
WHERE c.deleted_at IS NULL;
