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 Shrink.
12 *
13 * @category Elasticsearch
14 *
15 * @author  Zachary Tong <zach@elastic.co>
16 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
17 *
18 * @link http://elastic.co
19 */
20class Shrink extends AbstractEndpoint
21{
22    /**
23     * The name of the target index to shrink into
24     *
25     * @var string
26     */
27    private $target;
28
29    public function setBody($body): Shrink
30    {
31        if (isset($body) !== true) {
32            return $this;
33        }
34
35        $this->body = $body;
36
37        return $this;
38    }
39
40    public function setTarget(?string $target): Shrink
41    {
42        if (isset($target) !== true) {
43            return $this;
44        }
45        $this->target = $target;
46
47        return $this;
48    }
49
50    /**
51     * @throws \Elasticsearch\Common\Exceptions\RuntimeException
52     */
53    public function getURI(): string
54    {
55        if (isset($this->index) !== true) {
56            throw new Exceptions\RuntimeException(
57                'index is required for Shrink'
58            );
59        }
60        if (isset($this->target) !== true) {
61            throw new Exceptions\RuntimeException(
62                'target is required for Shrink'
63            );
64        }
65        return "/{$this->index}/_shrink/{$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