aboutsummaryrefslogtreecommitdiffhomepage
path: root/services/app/src/Models/AggregatedExecutionStatus.php
blob: 82b19e4c3f841901ac2901cd1727b29212f9c76a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php

declare(strict_types=1);

namespace Nsfisis\Albatross\Models;

enum AggregatedExecutionStatus: string
{
    case UpdateNeeded = 'UpdateNeeded';
    case Pending = 'Pending';
    case Failed = 'Failed';
    case OK = 'OK';

    public function label(): string
    {
        return match ($this) {
            self::UpdateNeeded => '実行待機中',
            self::Pending => '実行待機中',
            self::Failed => '失敗',
            self::OK => 'OK',
        };
    }

    public function showLoadingIndicator(): bool
    {
        return match ($this) {
            self::UpdateNeeded => true,
            self::Pending => true,
            self::Failed => false,
            self::OK => false,
        };
    }

    public function toInt(): int
    {
        return match ($this) {
            self::UpdateNeeded => 0,
            self::Pending => 1,
            self::Failed => 2,
            self::OK => 3,
        };
    }

    public static function fromInt(int $n): self
    {
        // @phpstan-ignore-next-line
        return match ($n) {
            0 => self::UpdateNeeded,
            1 => self::Pending,
            2 => self::Failed,
            3 => self::OK,
        };
    }
}