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: 'number',
19: * description?: non-empty-string,
20: * title?: non-empty-string,
21: * minimum?: float|int,
22: * maximum?: float|int,
23: * default?: float|int,
24: * }>
25: */
26: final readonly class NumberSchema implements PrimitiveSchemaDefinition
27: {
28: /**
29: * @var non-empty-string
30: */
31: public string $type;
32:
33: /**
34: * @param null|non-empty-string $description
35: * @param null|non-empty-string $title
36: */
37: public function __construct(
38: public ?string $description = null,
39: public ?string $title = null,
40: public null|float|int $minimum = null,
41: public null|float|int $maximum = null,
42: public null|float|int $default = null,
43: ) {
44: $this->type = 'number';
45: }
46:
47: #[\Override]
48: public function toArray(): array
49: {
50: return array_filter([
51: 'type' => $this->type,
52: 'description' => $this->description,
53: 'title' => $this->title,
54: 'minimum' => $this->minimum,
55: 'maximum' => $this->maximum,
56: 'default' => $this->default,
57: ], static fn(mixed $value): bool => null !== $value);
58: }
59:
60: /**
61: * @return template-type<self, PrimitiveSchemaDefinition, 'T'>
62: */
63: #[\Override]
64: public function jsonSerialize(): array
65: {
66: return $this->toArray();
67: }
68: }
69: