<?php

namespace App\Support;

use App\Events\NewNotification;
use App\Models\User;
use App\Notifications\AppNotification;

class Notifier
{
    public static function send(
        User    $recipient,
        string  $title,
        string  $body  = '',
        string  $icon  = 'fa-bell',
        string  $color = 'primary',
        ?string $url   = null,
    ): void {
        // Persist in DB so it shows on page reload
        $recipient->notify(new AppNotification($title, $body, $url, $icon, $color));

        // Broadcast in real-time to the bell dropdown
        broadcast(new NewNotification($recipient->id, $title, $body, $icon, $color, $url));
    }
}
