1<?php
2
3declare(strict_types = 1);
4
5namespace Elasticsearch\Endpoints;
6
7use Elasticsearch\Common\Exceptions\RuntimeException;
8
9/**
10 * Class Update
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 Update extends AbstractEndpoint
19{
20    public function setBody($body): Update
21    {
22        if (isset($body) !== true) {
23            return $this;
24        }
25
26        $this->body = $body;
27
28        return $this;
29    }
30
31    /**
32     * @throws RuntimeException
33     */
34    public function getURI(): string
35    {
36        if (isset($this->id) !== true) {
37            throw new RuntimeException(
38                'id is required for Update'
39            );
40        }
41        if (isset($this->index) !== true) {
42            throw new RuntimeException(
43                'index is required for Update'
44            );
45        }
46
47        $id = $this->id;
48        $index = $this->index;
49        $type = $this->type ?? null;
50
51        if (isset($type)) {
52            return "/$index/$type/$id/_update";
53        }
54        return "/$index/_update/$id";
55    }
56
57    public function getParamWhitelist(): array
58    {
59        return [
60            'wait_for_active_shards',
61            '_source',
62            '_source_excludes',
63            '_source_includes',
64            'lang',
65            'parent',
66            'refresh',
67            'retry_on_conflict',
68            'routing',
69            'timeout',
70            'if_seq_no',
71            'if_primary_term'
72        ];
73    }
74
75    public function getMethod(): string
76    {
77        return 'POST';
78    }
79}
80