1<?php
2
3declare(strict_types = 1);
4
5namespace Elasticsearch\Endpoints\Indices\Alias;
6
7use Elasticsearch\Common\Exceptions;
8use Elasticsearch\Endpoints\AbstractEndpoint;
9
10/**
11 * Class Exists
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 Exists extends AbstractEndpoint
20{
21    /**
22     * A comma-separated list of alias names to return
23     *
24     * @var string
25     */
26    private $name;
27
28    public function setName(?string $name): Exists
29    {
30        if (isset($name) !== true) {
31            return $this;
32        }
33
34        $this->name = $name;
35
36        return $this;
37    }
38
39    /**
40     * @throws \Elasticsearch\Common\Exceptions\RuntimeException
41     */
42    public function getURI(): string
43    {
44        if (isset($this->name) !== true) {
45            throw new Exceptions\RuntimeException(
46                'name is required for Exists'
47            );
48        }
49        $name = $this->name;
50        $index = $this->index ?? null;
51
52        if (isset($index)) {
53            return "/$index/_alias/$name";
54        }
55        return "/_alias/$name";
56    }
57
58    public function getParamWhitelist(): array
59    {
60        return [
61            'ignore_unavailable',
62            'allow_no_indices',
63            'expand_wildcards',
64            'local'
65        ];
66    }
67
68    public function getMethod(): string
69    {
70        return 'HEAD';
71    }
72}
73