<?php

namespace App\Services;

use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notification;
use Spatie\Permission\Models\Role;

class NotificationService
{
    public function send(Model $notifiable, Notification $notification): void
    {
        $notifiable->notify($notification);
    }

    public function sendToMany(Collection $notifiables, Notification $notification): void
    {
        foreach ($notifiables as $notifiable) {
            $notifiable->notify(clone $notification);
        }
    }

    public function sendToRole(string $role, Notification $notification): void
    {
        $users = Role::findByName($role)->users()->get();

        foreach ($users as $user) {
            $user->notify(clone $notification);
        }
    }
}
