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\NumberSchema;
17:
18: /**
19: * Fluent builder for {@see NumberSchema}.
20: *
21: * @extends PrimitiveSchemaDefinitionBuilder<float|int, array{
22: * type: 'number',
23: * description?: non-empty-string,
24: * title?: non-empty-string,
25: * minimum?: float|int,
26: * maximum?: float|int,
27: * default?: float|int,
28: * }>
29: */
30: final class NumberSchemaBuilder extends PrimitiveSchemaDefinitionBuilder
31: {
32: private null|float|int $minimum = null;
33: private null|float|int $maximum = null;
34:
35: public function minimum(float|int $minimum): self
36: {
37: $this->minimum = $minimum;
38:
39: return $this;
40: }
41:
42: public function maximum(float|int $maximum): self
43: {
44: $this->maximum = $maximum;
45:
46: return $this;
47: }
48:
49: #[\Override]
50: public function build(): NumberSchema
51: {
52: if (isset($this->minimum, $this->maximum) && $this->minimum > $this->maximum) {
53: throw new \LogicException('The minimum value cannot be greater than the maximum value.');
54: }
55:
56: if (isset($this->default, $this->minimum) && $this->default < $this->minimum) {
57: throw new \LogicException('The default value cannot be less than the minimum value.');
58: }
59:
60: if (isset($this->default, $this->maximum) && $this->default > $this->maximum) {
61: throw new \LogicException('The default value cannot be greater than the maximum value.');
62: }
63:
64: return new NumberSchema(
65: $this->description,
66: $this->title,
67: $this->minimum,
68: $this->maximum,
69: $this->default,
70: );
71: }
72: }
73: