Modellwahl über Kanalfähigkeiten mit erklärten Einschränkungen, Abgleich alter Werte, Ausführungsvarianten je Modul, getrennte Vertrags-/Buchungsinformation, Warten auf die Portalbestätigung mit Eskalation und Wiederaufnahme (Fälle C und D getestet). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
119 lines
5.6 KiB
PHP
119 lines
5.6 KiB
PHP
<?php
|
|
|
|
namespace App\Process;
|
|
|
|
use App\Models\Channel;
|
|
|
|
/**
|
|
* What a portal actually does for the landlord's account (K00 „Kanal-Fähigkeit“, docs/Prozessarchitektur/V2.1/02 §3). The
|
|
* admissible process models follow from it; the profile of the portal only suggests values. The value in force is, in
|
|
* this order: confirmed by an administrator · derived from an explicitly stored setting of the channel · suggested by the
|
|
* channel profile · unknown (blocks nothing, is shown as „please confirm“).
|
|
*/
|
|
final class ChannelCapabilities
|
|
{
|
|
public const COLLECTS_PAYMENT = 'collects_payment';
|
|
|
|
public const PROVIDES_CONTRACT_DOCUMENTS = 'provides_contract_documents';
|
|
|
|
public const MESSAGES_GUEST = 'messages_guest';
|
|
|
|
public const SENDS_CONFIRMATION_MAIL = 'sends_confirmation_mail';
|
|
|
|
/** Older stored settings that imply a capability: capability => [setting, value that means yes, value that means no]. */
|
|
private const LEGACY = [
|
|
self::COLLECTS_PAYMENT => ['payments', 'portal', 'landlord'],
|
|
self::PROVIDES_CONTRACT_DOCUMENTS => ['documents', 'portal', 'landlord'],
|
|
self::MESSAGES_GUEST => ['guest_messages', 'portal', 'landlord'],
|
|
];
|
|
|
|
/**
|
|
* @return array<string, array{label: string, question: string}>
|
|
*/
|
|
public static function definitions(): array
|
|
{
|
|
return [
|
|
self::COLLECTS_PAYMENT => ['label' => 'Inkasso', 'question' => 'Zieht das Portal das Geld des Gastes ein?'],
|
|
self::PROVIDES_CONTRACT_DOCUMENTS => ['label' => 'Vertragsunterlagen', 'question' => 'Stellt das Portal dem Gast die verbindlichen Vertragsunterlagen bereit?'],
|
|
self::MESSAGES_GUEST => ['label' => 'Gastkommunikation', 'question' => 'Schreibt das Portal den Gast an (Anreise-Information, Erinnerungen)?'],
|
|
self::SENDS_CONFIRMATION_MAIL => ['label' => 'Bestätigungsmail', 'question' => 'Schickt das Portal Ihnen eine Buchungsbestätigung per E-Mail?'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* The capabilities of a channel; a draft (key => bool|null) overrides what is stored, to show what a change would do.
|
|
*
|
|
* @param array<string, bool|null>|null $draft
|
|
* @return array<string, Capability>
|
|
*/
|
|
public function resolve(Channel $channel, ?array $draft = null): array
|
|
{
|
|
$stored = (array) (($channel->settings ?? [])['capabilities'] ?? []);
|
|
$legacy = (array) (($channel->process_overrides ?? [])['booking'] ?? []);
|
|
$suggested = (array) (config('channels.portal_profiles.'.app(ChannelProcessConfiguration::class)->profileKey($channel).'.capabilities') ?? []);
|
|
$result = [];
|
|
|
|
foreach (array_keys(self::definitions()) as $key) {
|
|
if ($draft !== null && array_key_exists($key, $draft) && $draft[$key] !== null && $draft[$key] !== '') {
|
|
// A value the landlord only left as shown keeps its origin; a changed one is a pending confirmation.
|
|
$value = filter_var($draft[$key], FILTER_VALIDATE_BOOLEAN);
|
|
$base = $this->resolve($channel)[$key];
|
|
if ($base->value !== $value) {
|
|
$result[$key] = new Capability($key, $value, Capability::CONFIRMED, null, now()->toIso8601String(), auth()->user()?->name);
|
|
|
|
continue;
|
|
}
|
|
}
|
|
if (isset($stored[$key]['value'])) {
|
|
$result[$key] = new Capability($key, (bool) $stored[$key]['value'], Capability::CONFIRMED, null, $stored[$key]['at'] ?? null, $stored[$key]['by'] ?? null);
|
|
|
|
continue;
|
|
}
|
|
if (isset(self::LEGACY[$key]) && filled($legacy[self::LEGACY[$key][0]] ?? null)) {
|
|
[$setting, $yes, $no] = self::LEGACY[$key];
|
|
$value = (string) $legacy[$setting];
|
|
if (in_array($value, [$yes, $no], true)) {
|
|
$result[$key] = new Capability($key, $value === $yes, Capability::DERIVED, $value === $yes ? 'Portal' : 'wir');
|
|
|
|
continue;
|
|
}
|
|
}
|
|
$result[$key] = array_key_exists($key, $suggested) && $suggested[$key] !== null
|
|
? new Capability($key, (bool) $suggested[$key], Capability::SUGGESTED)
|
|
: new Capability($key, null, Capability::UNKNOWN);
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
public function value(Channel $channel, string $key): ?bool
|
|
{
|
|
return $this->resolve($channel)[$key]->value;
|
|
}
|
|
|
|
/**
|
|
* What is stored to confirm the capabilities of a draft, and the readable list of what changed.
|
|
*
|
|
* @param array<string, bool|string|null> $draft
|
|
* @return array{capabilities: array<string, array{value: bool, at: string, by: ?string}>, changes: list<string>}
|
|
*/
|
|
public function confirm(Channel $channel, array $draft, ?string $by): array
|
|
{
|
|
$stored = (array) (($channel->settings ?? [])['capabilities'] ?? []);
|
|
$changes = [];
|
|
foreach (self::definitions() as $key => $definition) {
|
|
if (! array_key_exists($key, $draft) || $draft[$key] === null || $draft[$key] === '') {
|
|
continue;
|
|
}
|
|
$value = filter_var($draft[$key], FILTER_VALIDATE_BOOLEAN);
|
|
if (isset($stored[$key]['value']) && (bool) $stored[$key]['value'] === $value) {
|
|
continue;
|
|
}
|
|
$changes[] = $definition['label'].': '.(isset($stored[$key]['value']) ? ($stored[$key]['value'] ? 'ja' : 'nein').' → ' : '').($value ? 'ja' : 'nein');
|
|
$stored[$key] = ['value' => $value, 'at' => now()->toIso8601String(), 'by' => $by];
|
|
}
|
|
|
|
return ['capabilities' => $stored, 'changes' => $changes];
|
|
}
|
|
}
|