1<?php
2
3declare(strict_types = 1);
4
5namespace Elasticsearch\Endpoints\Snapshot;
6
7use Elasticsearch\Endpoints\AbstractEndpoint;
8use Elasticsearch\Common\Exceptions;
9
10/**
11 * Class Status
12 *
13 * @category Elasticsearch
14 * @package  Elasticsearch\Endpoints\Snapshot
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 Status extends AbstractEndpoint
20{
21    /**
22     * A comma-separated list of repository names
23     *
24     * @var string
25     */
26    private $repository;
27
28    /**
29     * A comma-separated list of snapshot names
30     *
31     * @var string
32     */
33    private $snapshot;
34
35    public function setRepository(?string $repository): Status
36    {
37        if (isset($repository) !== true) {
38            return $this;
39        }
40
41        $this->repository = $repository;
42
43        return $this;
44    }
45
46    public function setSnapshot(?string $snapshot): Status
47    {
48        if (isset($snapshot) !== true) {
49            return $this;
50        }
51
52        $this->snapshot = $snapshot;
53
54        return $this;
55    }
56
57    /**
58     * @throws \Elasticsearch\Common\Exceptions\RuntimeException
59     */
60    public function getURI(): string
61    {
62        $repository = $this->repository ?? null;
63        $snapshot   = $this->snapshot ?? null;
64
65        if (isset($snapshot) && isset($repository)) {
66            return "/_snapshot/$repository/$snapshot/_status";
67        }
68        if (isset($repository)) {
69            return "/_snapshot/$repository/_status";
70        }
71        return "/_snapshot/_status";
72    }
73
74    public function getParamWhitelist(): array
75    {
76        return [
77            'master_timeout',
78            'ignore_unavailable'
79        ];
80    }
81
82    public function getMethod(): string
83    {
84        return 'GET';
85    }
86}
87