77 lines
2.6 KiB
PHP
77 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Actions\Notifications;
|
|
|
|
use App\Enums\DiscordAllowedMentionType;
|
|
use App\Enums\NotificationChannel;
|
|
use App\Enums\NotificationEventType;
|
|
use App\Enums\NotificationFilterAttribute;
|
|
use App\Enums\NotificationFilterOperator;
|
|
use App\Http\Resources\NotificationActionResource;
|
|
use App\Http\Resources\ProjectResource;
|
|
use App\Models\Project;
|
|
|
|
class BuildProjectNotificationSettingsPayload
|
|
{
|
|
public function __construct(
|
|
private readonly ListProjectNotificationActions $listProjectNotificationActions,
|
|
) {}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function handle(Project $project, mixed $status = null): array
|
|
{
|
|
return [
|
|
'channelOptions' => NotificationChannel::options(),
|
|
'eventTypeOptions' => NotificationEventType::options(),
|
|
'filterAttributeOptions' => NotificationFilterAttribute::options(),
|
|
'filterOperatorOptions' => NotificationFilterOperator::options(),
|
|
'discordAllowedMentionOptions' => DiscordAllowedMentionType::options(),
|
|
'notificationActions' => NotificationActionResource::collection(
|
|
$this->listProjectNotificationActions->handle($project),
|
|
)->resolve(),
|
|
'project' => ProjectResource::make($project)->resolve(),
|
|
'status' => $status,
|
|
'templateVariables' => $this->templateVariables(),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array<int, array{description: string, value: string}>
|
|
*/
|
|
private function templateVariables(): array
|
|
{
|
|
return [
|
|
[
|
|
'description' => 'Absolute ticket URL for the notification event.',
|
|
'value' => '$url',
|
|
],
|
|
[
|
|
'description' => 'Project ticket key such as CORE-42.',
|
|
'value' => '$ticket_key',
|
|
],
|
|
[
|
|
'description' => 'Ticket title for the notification event.',
|
|
'value' => '$ticket_title',
|
|
],
|
|
[
|
|
'description' => 'Project name that owns the ticket.',
|
|
'value' => '$project_name',
|
|
],
|
|
[
|
|
'description' => 'Origin status label for status moves; blank for ticket create.',
|
|
'value' => '$status_from',
|
|
],
|
|
[
|
|
'description' => 'Destination or initial status label for the ticket event.',
|
|
'value' => '$status_to',
|
|
],
|
|
[
|
|
'description' => 'Actor name when the event has a known user.',
|
|
'value' => '$actor_name',
|
|
],
|
|
];
|
|
}
|
|
}
|