84 lines
1.9 KiB
PHP
84 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Notifications;
|
|
|
|
use App\Services\MobileDeepLink;
|
|
use Illuminate\Support\Arr;
|
|
|
|
class EngagementReminderNotification extends MobileNotification
|
|
{
|
|
private const MESSAGE_KEYS = [
|
|
'publish_meal',
|
|
'meal_photo',
|
|
'evening_checkin',
|
|
'community_inspiration',
|
|
'workout_checkin',
|
|
];
|
|
|
|
public function __construct(private readonly string $messageKey)
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
public static function randomMessageKey(): string
|
|
{
|
|
return Arr::random(self::MESSAGE_KEYS);
|
|
}
|
|
|
|
/**
|
|
* @return list<string>
|
|
*/
|
|
public static function messageKeys(): array
|
|
{
|
|
return self::MESSAGE_KEYS;
|
|
}
|
|
|
|
protected function category(): string
|
|
{
|
|
return self::CATEGORY_ENGAGEMENT;
|
|
}
|
|
|
|
protected function payload(object $notifiable): array
|
|
{
|
|
$message = $this->message();
|
|
|
|
return [
|
|
'type' => 'engagement_reminder',
|
|
'title' => $message['title'],
|
|
'body' => $message['body'],
|
|
'url' => MobileDeepLink::to($this->path()),
|
|
'data' => [
|
|
'message_key' => $this->messageKey,
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array{title: string, body: string}
|
|
*/
|
|
private function message(): array
|
|
{
|
|
$message = trans("api.notifications.engagement_reminders.{$this->messageKey}");
|
|
|
|
if (is_array($message)) {
|
|
return $message;
|
|
}
|
|
|
|
$fallback = trans('api.notifications.engagement_reminders.publish_meal');
|
|
|
|
return is_array($fallback)
|
|
? $fallback
|
|
: [
|
|
'title' => 'Bowli',
|
|
'body' => 'Publie ton plat du jour quand tu as un moment.',
|
|
];
|
|
}
|
|
|
|
private function path(): string
|
|
{
|
|
return $this->messageKey === 'workout_checkin'
|
|
? 'profile/workouts?create=1'
|
|
: 'create';
|
|
}
|
|
}
|