1: <?php
2:
3: declare(strict_types=1);
4:
5: /**
6: * This file is part of the Nexus MCP SDK package.
7: *
8: * (c) 2026 John Paul E. Balandan, CPA <paulbalandan@gmail.com>
9: *
10: * For the full copyright and license information, please view
11: * the LICENSE file that was distributed with this source code.
12: */
13:
14: namespace Nexus\Mcp\Core\Schema\Elicitation;
15:
16: use Nexus\Assert\Assert;
17: use Nexus\Mcp\Core\Schema\Arrayable;
18:
19: /**
20: * A single `{const, title}` entry inside a titled enum schema's option list.
21: *
22: * @implements Arrayable<array{const: non-empty-string, title: non-empty-string}>
23: *
24: * @see https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/schema/2025-11-25/schema.ts
25: */
26: final readonly class EnumOption implements Arrayable
27: {
28: /**
29: * @var non-empty-string
30: */
31: public string $const;
32:
33: /**
34: * @var non-empty-string
35: */
36: public string $title;
37:
38: public function __construct(string $const, string $title)
39: {
40: Assert::that($const)->isNonEmptyString('"oneOf.const" must be a non-empty string.');
41: Assert::that($title)->isNonEmptyString('"oneOf.title" must be a non-empty string.');
42:
43: $this->const = $const;
44: $this->title = $title;
45: }
46:
47: /**
48: * @param array<string, mixed> $data
49: */
50: #[\Override]
51: public static function fromArray(array $data): static
52: {
53: Assert::that($data)->hasOffset('const', '"oneOf" missing the required "const" key.');
54: $const = $data['const'];
55: Assert::that($const)->isString('"oneOf.const" must be a string, {type} given.');
56:
57: Assert::that($data)->hasOffset('title', '"oneOf" missing the required "title" key.');
58: $title = $data['title'];
59: Assert::that($title)->isString('"oneOf.title" must be a string, {type} given.');
60:
61: return new self($const, $title);
62: }
63:
64: #[\Override]
65: public function toArray(): array
66: {
67: return [
68: 'const' => $this->const,
69: 'title' => $this->title,
70: ];
71: }
72:
73: #[\Override]
74: public function jsonSerialize(): array
75: {
76: return $this->toArray();
77: }
78: }
79: