<?php

declare(strict_types=1);

namespace App\Enums;

/**
 * Platform roles. Marketplace participation (buying and selling) is not a role
 * -- every account can do both -- so this enum only describes staff privilege.
 */
enum UserRole: string
{
    case User = 'user';
    case Support = 'support';
    case Admin = 'admin';
    case SuperAdmin = 'super_admin';

    public function isStaff(): bool
    {
        return $this !== self::User;
    }

    /**
     * Higher wins. Used for "at least this role" checks so new roles can be
     * inserted without rewriting every gate.
     */
    public function level(): int
    {
        return match ($this) {
            self::User => 0,
            self::Support => 10,
            self::Admin => 20,
            self::SuperAdmin => 30,
        };
    }

    public function atLeast(self $other): bool
    {
        return $this->level() >= $other->level();
    }

    public function label(): string
    {
        return match ($this) {
            self::User => 'Member',
            self::Support => 'Support',
            self::Admin => 'Administrator',
            self::SuperAdmin => 'Super administrator',
        };
    }
}
