HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: /home/xedaptot/ai.naniguide.com/app/Notifications/Admin/SendingServerWebhookProcessedSuccess.php
<?php

namespace App\Notifications\Admin;

use App\Model\BounceLog;
use App\Model\FeedbackLog;
use App\Model\SendingServer;
use App\Notifications\AppNotification;
use Illuminate\Database\Eloquent\Model;

/**
 * One bounce / complaint successfully recorded. Body shows Customer name +
 * Campaign name (resolved via tracking_log) so admin can read the inbox
 * without clicking through to the log row.
 */
class SendingServerWebhookProcessedSuccess extends AppNotification
{
    /** $log is BounceLog or FeedbackLog. */
    public function __construct(
        public SendingServer $server,
        public Model $log,
        public string $kind   // 'bounce' | 'complaint'
    ) {}

    public function audience(): string { return self::AUDIENCE_ADMINS; }
    public function category(): string { return self::CATEGORY_INFO; }
    public function severity(): string { return self::SEVERITY_SUCCESS; }

    public function subject(): ?Model
    {
        return $this->log;
    }

    public function toArray(object $notifiable = null): array
    {
        $tracking = method_exists($this->log, 'trackingLog') ? $this->log->trackingLog : null;
        $customerName = $tracking?->customer?->displayName() ?? '(orphan customer)';
        $campaignName = $tracking?->campaign?->name ?? '(no campaign)';

        $rawType = $this->kind === 'bounce'
            ? ($this->log->bounce_type ?? '?')
            : ($this->log->feedback_type ?? '?');

        $logId   = $this->log->getKey();
        $logName = $this->kind === 'bounce' ? 'BounceLog' : 'FeedbackLog';

        return [
            'title' => sprintf('%s recorded — %s / %s', ucfirst($this->kind), $customerName, $campaignName),
            'body'  => sprintf(
                '%s #%s (type=%s) on %s server "%s" — Customer: %s, Campaign: %s, Recipient runtime_message_id: %s',
                $logName,
                $logId,
                $rawType,
                $this->server->type,
                $this->server->name ?? ('#' . $this->server->id),
                $customerName,
                $campaignName,
                $this->log->runtime_message_id ?? '?'
            ),
        ];
    }
}