41 lines
1.2 KiB
PHP
41 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Communication;
|
|
|
|
use App\Enums\Medium;
|
|
use App\Enums\MessageEffect;
|
|
use App\Enums\MessageIntent;
|
|
use App\Models\Booking;
|
|
|
|
/**
|
|
* What the process core decided about a message (V2.1): intent, case (only if verified), the effects that apply and why.
|
|
*/
|
|
final readonly class MessageDecision
|
|
{
|
|
/**
|
|
* @param list<MessageEffect> $effects applied effects, in order
|
|
* @param list<string> $reasons plain-language explanation
|
|
*/
|
|
public function __construct(
|
|
public Medium $medium,
|
|
public MessageIntent $intent,
|
|
public ?Booking $booking,
|
|
public array $effects,
|
|
public array $reasons,
|
|
) {}
|
|
|
|
public function has(MessageEffect $effect): bool
|
|
{
|
|
return in_array($effect, $this->effects, true);
|
|
}
|
|
|
|
/**
|
|
* @return array{medium: string, intent: string, booking_id: ?int, effects: list<string>, reasons: list<string>}
|
|
*/
|
|
public function toArray(): array
|
|
{
|
|
return ['medium' => $this->medium->value, 'intent' => $this->intent->value, 'booking_id' => $this->booking?->id,
|
|
'effects' => array_map(fn (MessageEffect $effect): string => $effect->value, $this->effects), 'reasons' => $this->reasons];
|
|
}
|
|
}
|