period === 'morning' ? 'scheduled_morning' : 'scheduled_evening'; // Candidates: users who have explicitly opted in to WhatsApp. // Per-user tier + daily-limit + scheduled-updates checks happen via // canSendNow('whatsapp'); that single call covers tier eligibility // (canUseChannel) AND today's notification_log count. $userIds = UserNotificationPreference::where('channel', 'whatsapp') ->where('enabled', true) ->distinct() ->pluck('user_id'); User::whereIn('id', $userIds) ->chunkById(500, function (Collection $users) use ($triggerType): void { foreach ($users as $user) { if (! PlanFeatures::for($user)->canSendNow('whatsapp')) { continue; } DispatchUserNotificationJob::dispatch($user, $triggerType, fuelType: 'all'); } }); } }