getKey(), tenantName: $tenant->name, presentation: $presentation, removedFromWorkspace: $tenant->isRemovedFromWorkspace(), workspaceClosed: (bool) $tenant->workspace?->isClosed(), contextNote: self::contextNoteFor($presentation, $tenant->isRemovedFromWorkspace(), (bool) $tenant->workspace?->isClosed()), ); } public static function forInvalid(string $viewerContext, ?ManagedEnvironment $tenant = null, ?string $normalizedValue = null): self { return new self( viewerContext: $viewerContext, tenantId: $tenant instanceof ManagedEnvironment ? (int) $tenant->getKey() : null, tenantName: $tenant?->name, presentation: TenantLifecyclePresentation::invalid($normalizedValue), removedFromWorkspace: $tenant?->isRemovedFromWorkspace() ?? false, workspaceClosed: (bool) $tenant?->workspace?->isClosed(), contextNote: 'Some tenant follow-up actions may be unavailable from this canonical workspace view.', ); } public function selectorAvailabilityMessage(): ?string { if ($this->removedFromWorkspace) { return 'This tenant was removed from its workspace and may not appear in the tenant selector.'; } if ($this->workspaceClosed) { return 'This tenant belongs to a closed workspace and may not appear in active tenant context.'; } if ($this->presentation->isInvalidFallback) { return 'This tenant has an invalid lifecycle value and may not appear in the tenant selector.'; } if (! $this->presentation->isSelectableAsContext()) { return 'This tenant is currently '.$this->presentation->lowercaseLabel().' and may not appear in the tenant selector.'; } return null; } private static function contextNoteFor(TenantLifecyclePresentation $presentation, bool $removedFromWorkspace, bool $workspaceClosed): ?string { if ($removedFromWorkspace || $workspaceClosed) { return 'Historical operation context remains available, but active tenant follow-up actions are unavailable from this canonical workspace view.'; } if ($presentation->isInvalidFallback || ! $presentation->isSelectableAsContext()) { return 'Some tenant follow-up actions may be unavailable from this canonical workspace view.'; } return null; } }