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