1<?php
2
3declare(strict_types = 1);
4
5namespace Elasticsearch\Endpoints;
6
7use Elasticsearch\Common\Exceptions;
8
9/**
10 * Class Scroll
11 *
12 * @category Elasticsearch
13 * @package  Elasticsearch\Endpoints
14 * @author   Zachary Tong <zach@elastic.co>
15 * @license  http://www.apache.org/licenses/LICENSE-2.0 Apache2
16 * @link     http://elastic.co
17 */
18class Scroll extends AbstractEndpoint
19{
20    protected $scrollId;
21
22    public function setBody($body): Scroll
23    {
24        if (isset($body) !== true) {
25            return $this;
26        }
27
28        $this->body = $body;
29
30        return $this;
31    }
32
33    /**
34     * @return $this
35     */
36    public function setScrollId(?string $scrollId): Scroll
37    {
38        if ($scrollId !== null) {
39            $this->scrollId = $scrollId;
40        }
41        return $this;
42    }
43
44    public function getURI(): string
45    {
46        $scrollId = $this->scrollId ?? null;
47
48        if (isset($scrollId)) {
49            return "/_search/scroll/$scrollId";
50        }
51
52        return "/_search/scroll";
53    }
54
55    public function getParamWhitelist(): array
56    {
57        return [
58            'scroll',
59            'scroll_id',
60            'rest_total_hits_as_int'
61        ];
62    }
63
64    public function getMethod(): string
65    {
66        return isset($this->body) ? 'POST' : 'GET';
67    }
68}
69