*/ final class ElicitResult implements ResultInterface { /** * @param ElicitAction $action The user's action in response to the elicitation * @param array|null $content The content provided by the user (only present when action is "accept") */ public function __construct( public readonly ElicitAction $action, public readonly ?array $content = null, ) { } /** * @param array{action: string, content?: array} $data */ public static function fromArray(array $data): self { if (!isset($data['action']) || !\is_string($data['action'])) { throw new InvalidArgumentException('Missing or invalid "action" in ElicitResult data.'); } $action = ElicitAction::from($data['action']); $content = isset($data['content']) && \is_array($data['content']) ? $data['content'] : null; if (ElicitAction::Accept === $action && null === $content) { throw new InvalidArgumentException('Content must be provided when action is "accept".'); } return new self($action, $content); } public function isAccepted(): bool { return ElicitAction::Accept === $this->action; } public function isDeclined(): bool { return ElicitAction::Decline === $this->action; } public function isCancelled(): bool { return ElicitAction::Cancel === $this->action; } /** * @return array{action: string, content?: array} */ public function jsonSerialize(): array { $result = [ 'action' => $this->action->value, ]; if (null !== $this->content) { $result['content'] = $this->content; } return $result; } }