<?php

namespace App\Enums;

enum UserRole: int {
    case Viewer = 100;
    case Manager = 200;

    public static function tryFromName(string $name): ?self
    {
        return match (strtolower($name)) {
            'manager' => self::Manager,
            'viewer' => self::Viewer,
            default => null,
        };
    }

    public function label(): string
    {
        return $this->name;
    }

    public static function labels(): array
    {
        return collect(self::cases())->mapWithKeys(function ($role) {
            return [$role->value => $role->label()];
        })->toArray();
    }
}
