trashed() || $lifecycle === TenantLifecycle::Archived; return new TenantOperabilityDecision( lifecycle: $lifecycle, canViewTenantSurface: $lifecycle->canViewTenantSurface(), canSelectAsContext: ! $tenant->trashed() && $lifecycle->canSelectAsContext(), canOperate: ! $tenant->trashed() && $lifecycle->canOperate(), canArchive: ! $isArchived && $lifecycle->canArchive(), canRestore: $isArchived || $lifecycle->canRestore(), canResumeOnboarding: ! $tenant->trashed() && $lifecycle->canResumeOnboarding(), canReferenceInWorkspaceMonitoring: $lifecycle->canReferenceInWorkspaceMonitoring(), ); } public function lifecycleFor(Tenant $tenant): TenantLifecycle { return $this->decisionFor($tenant)->lifecycle; } public function canSelectAsContext(Tenant $tenant): bool { return $this->decisionFor($tenant)->canSelectAsContext; } public function canViewTenantSurface(Tenant $tenant): bool { return $this->decisionFor($tenant)->canViewTenantSurface; } public function canResumeOnboarding(Tenant $tenant): bool { return $this->decisionFor($tenant)->canResumeOnboarding; } public function canReferenceInWorkspaceMonitoring(Tenant $tenant): bool { return $this->decisionFor($tenant)->canReferenceInWorkspaceMonitoring; } /** * @param Collection $tenants * @return Collection */ public function filterSelectable(Collection $tenants): Collection { return $tenants ->filter(fn (mixed $tenant): bool => $tenant instanceof Tenant && $this->canSelectAsContext($tenant)) ->values(); } public function applySelectableScope(Builder $query, ?string $table = null): Builder { $prefix = $table !== null && $table !== '' ? "{$table}." : ''; return $query ->whereNull("{$prefix}deleted_at") ->where("{$prefix}status", TenantLifecycle::Active->value); } }