1<?php
2
3declare(strict_types = 1);
4
5namespace Elasticsearch\Endpoints\Indices\Settings;
6
7use Elasticsearch\Endpoints\AbstractEndpoint;
8use Elasticsearch\Common\Exceptions;
9
10/**
11 * Class Put
12 *
13 * @category Elasticsearch
14 * @package  Elasticsearch\Endpoints\Indices\Settings
15 * @author   Zachary Tong <zach@elastic.co>
16 * @license  http://www.apache.org/licenses/LICENSE-2.0 Apache2
17 * @link     http://elastic.co
18 */
19class Put extends AbstractEndpoint
20{
21    /**
22     * @throws \Elasticsearch\Common\Exceptions\InvalidArgumentException
23     */
24    public function setBody($body): Put
25    {
26        if (isset($body) !== true) {
27            return $this;
28        }
29
30        $this->body = $body;
31
32        return $this;
33    }
34
35    public function getURI(): string
36    {
37        $index = $this->index ?? null;
38        if (isset($index)) {
39            return "/$index/_settings";
40        }
41        return "/_settings";
42    }
43
44    public function getParamWhitelist(): array
45    {
46        return [
47            'master_timeout',
48            'timeout',
49            'preserve_existing',
50            'ignore_unavailable',
51            'allow_no_indices',
52            'expand_wildcards',
53            'flat_settings'
54        ];
55    }
56
57    /**
58     * @throws \Elasticsearch\Common\Exceptions\RuntimeException
59     */
60    public function getBody()
61    {
62        if (isset($this->body) !== true) {
63            throw new Exceptions\RuntimeException('Body is required for Put Settings');
64        }
65
66        return $this->body;
67    }
68
69    public function getMethod(): string
70    {
71        return 'PUT';
72    }
73}
74