'激活', self::INACTIVE => '未激活', self::DISABLED => '禁用', self::MAINTENANCE => '维护中', self::ERROR => '错误', self::TESTING => '测试中', self::EXPIRED => '已过期', }; } /** * 获取状态的详细描述 * * @return string */ public function getDescription(): string { return match ($this) { self::ACTIVE => '服务正常运行,可以正常调用API', self::INACTIVE => '服务未激活,暂时无法使用', self::DISABLED => '服务已被禁用,不允许调用API', self::MAINTENANCE => '服务正在维护中,暂时不可用', self::ERROR => '服务出现错误,需要检查配置', self::TESTING => '服务处于测试状态,仅限测试使用', self::EXPIRED => '服务已过期,需要续费或重新配置', }; } /** * 获取状态的颜色 * * @return string */ public function getColor(): string { return match ($this) { self::ACTIVE => 'success', self::INACTIVE => 'secondary', self::DISABLED => 'danger', self::MAINTENANCE => 'warning', self::ERROR => 'danger', self::TESTING => 'info', self::EXPIRED => 'dark', }; } /** * 获取状态的图标 * * @return string */ public function getIcon(): string { return match ($this) { self::ACTIVE => 'fa-check-circle', self::INACTIVE => 'fa-pause-circle', self::DISABLED => 'fa-ban', self::MAINTENANCE => 'fa-tools', self::ERROR => 'fa-exclamation-triangle', self::TESTING => 'fa-flask', self::EXPIRED => 'fa-clock', }; } /** * 检查状态是否可用 * * @return bool */ public function isAvailable(): bool { return in_array($this, [self::ACTIVE, self::TESTING]); } /** * 检查状态是否需要关注 * * @return bool */ public function needsAttention(): bool { return in_array($this, [self::ERROR, self::EXPIRED, self::MAINTENANCE]); } /** * 检查状态是否可以调用API * * @return bool */ public function canCallApi(): bool { return $this === self::ACTIVE; } /** * 检查状态是否可以测试 * * @return bool */ public function canTest(): bool { return in_array($this, [self::ACTIVE, self::TESTING]); } /** * 获取优先级(数字越小优先级越高) * * @return int */ public function getPriority(): int { return match ($this) { self::ACTIVE => 1, self::TESTING => 2, self::INACTIVE => 3, self::MAINTENANCE => 4, self::DISABLED => 5, self::ERROR => 6, self::EXPIRED => 7, }; } /** * 获取状态的严重程度 * * @return string */ public function getSeverity(): string { return match ($this) { self::ACTIVE => 'INFO', self::INACTIVE => 'WARNING', self::DISABLED => 'ERROR', self::MAINTENANCE => 'WARNING', self::ERROR => 'CRITICAL', self::TESTING => 'INFO', self::EXPIRED => 'ERROR', }; } /** * 获取可以转换到的状态 * * @return array */ public function getAllowedTransitions(): array { return match ($this) { self::ACTIVE => [self::INACTIVE, self::DISABLED, self::MAINTENANCE, self::TESTING], self::INACTIVE => [self::ACTIVE, self::DISABLED, self::TESTING], self::DISABLED => [self::INACTIVE, self::TESTING], self::MAINTENANCE => [self::ACTIVE, self::INACTIVE, self::DISABLED], self::ERROR => [self::ACTIVE, self::INACTIVE, self::DISABLED, self::TESTING], self::TESTING => [self::ACTIVE, self::INACTIVE, self::DISABLED], self::EXPIRED => [self::INACTIVE, self::TESTING], }; } /** * 检查是否可以转换到指定状态 * * @param SERVICE_STATUS $targetStatus * @return bool */ public function canTransitionTo(SERVICE_STATUS $targetStatus): bool { return in_array($targetStatus, $this->getAllowedTransitions()); } /** * 获取所有状态的选项数组 * * @return array */ public static function getOptions(): array { $options = []; foreach (self::cases() as $case) { $options[$case->value] = $case->getLabel(); } return $options; } /** * 获取可用状态 * * @return array */ public static function getAvailableStatuses(): array { return array_filter(self::cases(), function ($case) { return $case->isAvailable(); }); } /** * 获取需要关注的状态 * * @return array */ public static function getAttentionStatuses(): array { return array_filter(self::cases(), function ($case) { return $case->needsAttention(); }); } /** * 按优先级排序状态 * * @return array */ public static function getSortedByPriority(): array { $statuses = self::cases(); usort($statuses, function ($a, $b) { return $a->getPriority() <=> $b->getPriority(); }); return $statuses; } }