fedi-feed-router/app/Services/Notification/NotificationService.php

69 lines
1.9 KiB
PHP

<?php
namespace App\Services\Notification;
use App\Enums\NotificationSeverityEnum;
use App\Enums\NotificationTypeEnum;
use App\Models\Notification;
use Illuminate\Database\Eloquent\Model;
class NotificationService
{
/**
* @param array<string, mixed> $data
*/
public function send(
NotificationTypeEnum $type,
NotificationSeverityEnum $severity,
string $title,
string $message,
?Model $notifiable = null,
array $data = [],
): Notification {
return Notification::create([
'type' => $type,
'severity' => $severity,
'title' => $title,
'message' => $message,
'data' => $data ?: null,
'notifiable_type' => $notifiable?->getMorphClass(),
'notifiable_id' => $notifiable?->getKey(),
]);
}
/**
* @param array<string, mixed> $data
*/
public function info(
string $title,
string $message,
?Model $notifiable = null,
array $data = [],
): Notification {
return $this->send(NotificationTypeEnum::GENERAL, NotificationSeverityEnum::INFO, $title, $message, $notifiable, $data);
}
/**
* @param array<string, mixed> $data
*/
public function warning(
string $title,
string $message,
?Model $notifiable = null,
array $data = [],
): Notification {
return $this->send(NotificationTypeEnum::GENERAL, NotificationSeverityEnum::WARNING, $title, $message, $notifiable, $data);
}
/**
* @param array<string, mixed> $data
*/
public function error(
string $title,
string $message,
?Model $notifiable = null,
array $data = [],
): Notification {
return $this->send(NotificationTypeEnum::GENERAL, NotificationSeverityEnum::ERROR, $title, $message, $notifiable, $data);
}
}