find($this->eventPackageId); if (! $eventPackage) { Log::warning('Package threshold job skipped; event package missing', [ 'event_package_id' => $this->eventPackageId, ]); return; } $tenant = $eventPackage->event?->tenant; if (! $tenant) { return; } $preferences = app(\App\Services\Packages\TenantNotificationPreferences::class); if (! $preferences->shouldNotify($tenant, 'photo_thresholds')) { $this->logNotification($tenant, [ 'type' => 'photo_threshold', 'status' => 'skipped', 'context' => $this->context($eventPackage), ]); return; } $emails = collect([ $tenant->contact_email, $tenant->user?->email, ])->filter(fn ($email) => is_string($email) && filter_var($email, FILTER_VALIDATE_EMAIL)) ->unique(); if ($emails->isEmpty()) { Log::info('Package threshold notification skipped due to missing recipients', [ 'event_package_id' => $eventPackage->id, 'threshold' => $this->threshold, ]); $this->logNotification($tenant, [ 'type' => 'photo_threshold', 'status' => 'skipped', 'context' => array_merge($this->context($eventPackage), ['reason' => 'no_recipient']), ]); return; } $context = $this->context($eventPackage); $this->dispatchToRecipients( $tenant, $emails, 'photo_threshold', function (string $email) use ($eventPackage) { Notification::route('mail', $email)->notify( new EventPackagePhotoThresholdNotification( $eventPackage, $this->threshold, $this->limit, $this->used, ) ); }, $context ); } private function context(EventPackage $eventPackage): array { return [ 'event_package_id' => $eventPackage->id, 'event_id' => $eventPackage->event_id, 'threshold' => $this->threshold, 'limit' => $this->limit, 'used' => $this->used, ]; } }