File size: 987 Bytes
097eaf0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php

declare(strict_types=1);

namespace Firecrawl\Models;

final class JsonFormat
{
    private function __construct(
        private readonly ?string $prompt = null,
        /** @var array<string, mixed>|null */
        private readonly ?array $schema = null,
    ) {}

    /**
     * @param array<string, mixed>|null $schema
     */
    public static function with(
        ?string $prompt = null,
        ?array $schema = null,
    ): self {
        return new self($prompt, $schema);
    }

    /** @return array<string, mixed> */
    public function toArray(): array
    {
        return array_filter([
            'type' => 'json',
            'prompt' => $this->prompt,
            'schema' => $this->schema,
        ], fn (mixed $v): bool => $v !== null);
    }

    public function getPrompt(): ?string
    {
        return $this->prompt;
    }

    /** @return array<string, mixed>|null */
    public function getSchema(): ?array
    {
        return $this->schema;
    }
}