1<?php
2
3declare(strict_types = 1);
4
5namespace Elasticsearch\Endpoints\Indices\Alias;
6
7use Elasticsearch\Endpoints\AbstractEndpoint;
8use Elasticsearch\Common\Exceptions;
9
10/**
11 * Class Put
12 *
13 * @category Elasticsearch
14 * @package  Elasticsearch\Endpoints\Indices\Alias
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     * The name of the alias to be created or updated
23     *
24     * @var string
25     */
26    private $name;
27
28    public function setBody($body): Put
29    {
30        if (isset($body) !== true) {
31            return $this;
32        }
33
34        $this->body = $body;
35
36        return $this;
37    }
38
39    public function setName(?string $name): Put
40    {
41        if (isset($name) !== true) {
42            return $this;
43        }
44
45        $this->name = $name;
46
47        return $this;
48    }
49
50    /**
51     * @throws \Elasticsearch\Common\Exceptions\RuntimeException
52     */
53    public function getURI(): string
54    {
55        if (isset($this->name) !== true) {
56            throw new Exceptions\RuntimeException(
57                'name is required for Put'
58            );
59        }
60        if (isset($this->index) !== true) {
61            throw new Exceptions\RuntimeException(
62                'index is required for Put'
63            );
64        }
65        return "/{$this->index}/_alias/{$this->name}";
66    }
67
68    public function getParamWhitelist(): array
69    {
70        return [
71            'timeout',
72            'master_timeout'
73        ];
74    }
75
76    public function getMethod(): string
77    {
78        return 'PUT';
79    }
80}
81