1: <?php
2:
3: declare(strict_types=1);
4:
5: /**
6: * This file is part of the Nexus MCP SDK package.
7: *
8: * (c) 2025 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\Schema\Elicitation;
15:
16: /**
17: * @implements PrimitiveSchemaDefinition<array{
18: * type: 'string',
19: * enum: list<non-empty-string>,
20: * enumNames?: list<non-empty-string>,
21: * description?: non-empty-string,
22: * title?: non-empty-string,
23: * default?: non-empty-string,
24: * }>
25: */
26: final readonly class EnumSchema implements PrimitiveSchemaDefinition
27: {
28: /**
29: * @var non-empty-string
30: */
31: public string $type;
32:
33: /**
34: * @param list<non-empty-string> $enum
35: * @param null|list<non-empty-string> $enumNames
36: * @param null|non-empty-string $description
37: * @param null|non-empty-string $title
38: * @param null|non-empty-string $default
39: */
40: public function __construct(
41: public array $enum,
42: public ?array $enumNames = null,
43: public ?string $description = null,
44: public ?string $title = null,
45: public ?string $default = null,
46: ) {
47: $this->type = 'string';
48: }
49:
50: #[\Override]
51: public function toArray(): array
52: {
53: return array_filter([
54: 'type' => $this->type,
55: 'enum' => $this->enum,
56: 'enumNames' => $this->enumNames,
57: 'description' => $this->description,
58: 'title' => $this->title,
59: 'default' => $this->default,
60: ], static fn(mixed $value): bool => null !== $value);
61: }
62:
63: /**
64: * @return template-type<self, PrimitiveSchemaDefinition, 'T'>
65: */
66: #[\Override]
67: public function jsonSerialize(): array
68: {
69: return $this->toArray();
70: }
71: }
72: