<?php

declare(strict_types=1);

final class MyronLicenseTier
{
    public const CORE = 'core';
    public const PERSONAL = 'personal';
    public const PRO = 'pro';
    public const AGENCY = 'agency';
    public const ENTERPRISE = 'enterprise';
    public const PARTNER = 'partner';

    /**
     * @return list<string>
     */
    public static function known(): array
    {
        return [
            self::CORE,
            self::PERSONAL,
            self::PRO,
            self::AGENCY,
            self::ENTERPRISE,
            self::PARTNER,
        ];
    }

    public static function normalize(string $tier): string
    {
        $normalized = strtolower(trim($tier));
        return in_array($normalized, self::known(), true) ? $normalized : self::CORE;
    }

    public static function rank(string $tier): int
    {
        return match (self::normalize($tier)) {
            self::PERSONAL => 10,
            self::PRO => 20,
            self::AGENCY,
            self::PARTNER => 30,
            self::ENTERPRISE => 100,
            default => 0,
        };
    }

    public static function isAtLeast(string $tier, string $minimumTier): bool
    {
        return self::rank($tier) >= self::rank($minimumTier);
    }

    public static function isEnterprise(string $tier): bool
    {
        return self::normalize($tier) === self::ENTERPRISE;
    }
}
