value}.active", false); return $ceiling && ($this->narrowing()['media'][$medium->value]['active'] ?? true) !== false; } public function consentRequired(Medium $medium): bool { return (bool) config("communication.media.{$medium->value}.consent_required", false); } /** * @return list the effects the rules allow for the intent on the medium (never empty: review at least) */ public function effects(Medium $medium, MessageIntent $intent): array { /** @var list $ceiling */ $ceiling = config('communication.effects.'.$intent->value, [MessageEffect::Review]); $withdrawn = (array) ($this->narrowing()['effects'][$medium->value][$intent->value] ?? []); $allowed = array_values(array_filter($ceiling, fn (MessageEffect $effect): bool => ! in_array($effect->value, $withdrawn, true))); return $allowed === [] ? [MessageEffect::Review] : $allowed; } /** * @return array */ private function narrowing(): array { return (array) (Settings::tenant()?->communication_rules ?? []); } }