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\Builder;
15:
16: use Nexus\Mcp\Schema\Elicitation\PrimitiveSchemaDefinition;
17:
18: /**
19: * @template T
20: * @template U of array<string, mixed>
21: */
22: abstract class PrimitiveSchemaDefinitionBuilder
23: {
24: /**
25: * @var null|non-empty-string
26: */
27: protected ?string $description = null;
28:
29: /**
30: * @var null|non-empty-string
31: */
32: protected ?string $title = null;
33:
34: /**
35: * @var null|T
36: */
37: protected mixed $default = null;
38:
39: private bool $required = false;
40:
41: /**
42: * @param non-empty-string $name
43: */
44: protected function __construct(
45: public readonly string $name,
46: ) {}
47:
48: /**
49: * @param non-empty-string $name
50: */
51: public static function booleanSchema(string $name): BooleanSchemaBuilder
52: {
53: return new BooleanSchemaBuilder($name);
54: }
55:
56: /**
57: * @param non-empty-string $name
58: * @param list<non-empty-string> $enum
59: */
60: public static function enumSchema(string $name, array $enum): EnumSchemaBuilder
61: {
62: return new EnumSchemaBuilder($name, $enum);
63: }
64:
65: /**
66: * @param non-empty-string $name
67: */
68: public static function numberSchema(string $name): NumberSchemaBuilder
69: {
70: return new NumberSchemaBuilder($name);
71: }
72:
73: /**
74: * @param non-empty-string $name
75: */
76: public static function stringSchema(string $name): StringSchemaBuilder
77: {
78: return new StringSchemaBuilder($name);
79: }
80:
81: /**
82: * @param non-empty-string $description
83: */
84: public function description(string $description): static
85: {
86: $this->description = $description;
87:
88: return $this;
89: }
90:
91: /**
92: * @param non-empty-string $title
93: */
94: public function title(string $title): static
95: {
96: $this->title = $title;
97:
98: return $this;
99: }
100:
101: /**
102: * @param T $default
103: */
104: public function default(mixed $default): static
105: {
106: $this->default = $default;
107:
108: return $this;
109: }
110:
111: public function required(): static
112: {
113: $this->required = true;
114:
115: return $this;
116: }
117:
118: public function isRequired(): bool
119: {
120: return $this->required;
121: }
122:
123: /**
124: * @return PrimitiveSchemaDefinition<U>
125: */
126: abstract public function build(): PrimitiveSchemaDefinition;
127: }
128: