$values setting key => effective value * @param array $sources setting key => level the value came from */ public function __construct( public readonly IntakeKind $intake, public readonly CaseType $caseType, public readonly array $values, public readonly array $sources, public readonly ?string $frozenAt = null, public readonly string $origin = 'intake', ) {} /** * The case type of a constellation: internal occasions are A6; requests are A1 (own way) or A2 (intermediary); * binding external bookings are A3–A5 by who handles documents and payments. */ public static function caseTypeFor(IntakeKind $intake, bool $viaChannel, Responsibility $documents, Responsibility $payments): CaseType { return match ($intake) { IntakeKind::Internal => CaseType::A6, IntakeKind::Inquiry => $viaChannel ? CaseType::A2 : CaseType::A1, IntakeKind::Booking => match (true) { $documents === Responsibility::Portal => CaseType::A5, $payments === Responsibility::Portal => CaseType::A4, default => CaseType::A3, }, }; } public function value(ProcessSetting $setting): string|int|bool|null { return array_key_exists($setting->value, $this->values) ? $this->values[$setting->value] : $setting->default(); } public function source(ProcessSetting $setting): string { return $this->sources[$setting->value] ?? self::SYSTEM; } public function processing(): ProcessingMode { return ProcessingMode::tryFrom((string) $this->value(ProcessSetting::Processing)) ?? ProcessingMode::Manual; } public function preReservation(): bool { return (bool) $this->value(ProcessSetting::PreReservation); } public function holdHours(): int { return max(1, (int) $this->value(ProcessSetting::HoldHours)); } public function documents(): Responsibility { return Responsibility::tryFrom((string) $this->value(ProcessSetting::Documents)) ?? Responsibility::Landlord; } public function payments(): Responsibility { return Responsibility::tryFrom((string) $this->value(ProcessSetting::Payments)) ?? Responsibility::Landlord; } public function guestMessages(): Responsibility { return Responsibility::tryFrom((string) $this->value(ProcessSetting::GuestMessages)) ?? Responsibility::Landlord; } public function arrivalInfoDaysBefore(): int { return max(1, (int) $this->value(ProcessSetting::ArrivalInfoDaysBefore)); } public function dataRequestMode(): DataRequestMode { return DataRequestMode::tryFrom((string) $this->value(ProcessSetting::DataRequest)) ?? DataRequestMode::Approval; } /** * Minutes of the clarification hold of an incomplete request (E-033): the value for automatic requests when the * guest is asked automatically, otherwise the one for release or manual requests. 0 = no hold. */ public function clarificationHoldMinutes(): int { $setting = $this->dataRequestMode() === DataRequestMode::Automatic ? ProcessSetting::ClarificationHoldAutoMinutes : ProcessSetting::ClarificationHoldManualMinutes; return max(0, (int) $this->value($setting)); } public function remindersMax(): int { return max(0, (int) $this->value(ProcessSetting::DataRequestRemindersMax)); } public function followupsMax(): int { return max(0, (int) $this->value(ProcessSetting::DataRequestFollowupsMax)); } public function reminderHours(): int { return max(1, (int) $this->value(ProcessSetting::DataRequestReminderHours)); } public function guestLinkValidDays(): int { return max(1, (int) $this->value(ProcessSetting::GuestLinkValidDays)); } public function formRequiresAddress(): bool { return (bool) $this->value(ProcessSetting::FormRequiresAddress); } public function contractTemplateId(): ?int { $value = $this->value(ProcessSetting::ContractTemplate); return $value === null ? null : (int) $value; } /** * Plain words for a level, for the "where does this come from" hint. */ public static function sourceLabel(string $source): string { return match ($source) { self::TENANT => 'Ihre Standardeinstellung', self::PROPERTY => 'Abweichung der Wohnung', self::CHANNEL => 'Abweichung des Portals', self::WEBSITE => 'Einstellung der eigenen Webseite', self::CASE_TYPE => 'fest für diese Vorgangsart', self::MODEL => 'festgelegt durch das gewählte Ablaufmodell', 'migration' => 'aus dem bisherigen Stand übernommen', default => 'Grundeinstellung', }; } /** * The profile as it is frozen on the case (settings resolved live are left out). * * @return array{intake: string, case_type: string, values: array, sources: array, frozen_at: string, origin: string} */ public function toArray(): array { $live = array_flip(array_map(fn (ProcessSetting $setting): string => $setting->value, self::LIVE)); return [ 'intake' => $this->intake->value, 'case_type' => $this->caseType->value, 'values' => array_diff_key($this->values, $live), 'sources' => array_diff_key($this->sources, $live), 'frozen_at' => $this->frozenAt ?? now()->toIso8601String(), 'origin' => $this->origin, ]; } /** * @param array $data */ public static function fromArray(array $data): self { return new self( IntakeKind::tryFrom((string) ($data['intake'] ?? '')) ?? IntakeKind::Inquiry, CaseType::tryFrom((string) ($data['case_type'] ?? '')) ?? CaseType::A1, (array) ($data['values'] ?? []), (array) ($data['sources'] ?? []), isset($data['frozen_at']) ? (string) $data['frozen_at'] : null, (string) ($data['origin'] ?? 'intake'), ); } public function withOrigin(string $origin): self { return new self($this->intake, $this->caseType, $this->values, $this->sources, $this->frozenAt, $origin); } }