-- Update existing users with appropriate default permissions based on their roles

-- Set default permissions for all users
UPDATE User SET 
  canViewProducts = TRUE,
  canPurchaseProducts = TRUE
WHERE canViewProducts IS NULL OR canPurchaseProducts IS NULL;

-- Set permissions for regular users
UPDATE User SET 
  canAccessUserPortal = TRUE,
  canAccessAdminPanel = FALSE,
  canManageUsers = FALSE,
  canManageProducts = FALSE
WHERE role = 'USER';

-- Set permissions for moderators
UPDATE User SET 
  canAccessUserPortal = TRUE,
  canAccessAdminPanel = TRUE,
  canManageUsers = FALSE,
  canManageProducts = FALSE
WHERE role = 'MODERATOR';

-- Set permissions for admins
UPDATE User SET 
  canAccessUserPortal = TRUE,
  canAccessAdminPanel = TRUE,
  canManageUsers = FALSE,
  canManageProducts = TRUE
WHERE role = 'ADMIN';

-- Set permissions for super admins
UPDATE User SET 
  canAccessUserPortal = TRUE,
  canAccessAdminPanel = TRUE,
  canManageUsers = TRUE,
  canManageProducts = TRUE
WHERE role = 'SUPER_ADMIN';