AuditActorSnapshot::human($actor), $actor instanceof PlatformUser => AuditActorSnapshot::platform($actor), default => AuditActorSnapshot::fromLegacy( type: $actorType ?? AuditActorType::infer($action instanceof AuditActionId ? $action->value : $action, $actorId, $actorEmail, $actorName, $context), id: $actorId, email: $actorEmail, label: $actorName, ), }; return $this->auditRecorder->record( action: $action, context: $context, workspace: $workspace, tenant: $tenant, actor: $resolvedActor, target: new AuditTargetSnapshot( type: $resourceType, id: $resourceId, label: $targetLabel, ), outcome: $status, recordedAt: CarbonImmutable::now(), summary: $summary, operationRunId: $operationRunId, ); } /** * @param array $context */ public function logTenantLifecycleAction( Tenant $tenant, string|AuditActionId $action, array $context = [], User|PlatformUser|null $actor = null, string $status = 'success', ?string $summary = null, ): \App\Models\AuditLog { return $this->log( workspace: $tenant->workspace, action: $action, context: $context, actor: $actor, status: $status, resourceType: 'tenant', resourceId: (string) $tenant->getKey(), targetLabel: $tenant->name, summary: $summary, tenant: $tenant, ); } /** * @param array $bundle */ public function logSupportDiagnosticsOpened( Tenant $tenant, string $contextType, array $bundle, User|PlatformUser|null $actor = null, ?OperationRun $operationRun = null, ): \App\Models\AuditLog { $sectionCount = is_array($bundle['sections'] ?? null) ? count($bundle['sections']) : 0; $referenceCount = collect($bundle['sections'] ?? []) ->sum(static fn (mixed $section): int => is_array($section) && is_array($section['references'] ?? null) ? count($section['references']) : 0); return $this->log( workspace: $tenant->workspace, action: AuditActionId::SupportDiagnosticsOpened, context: [ 'context_type' => $contextType, 'redaction_mode' => 'default_redacted', 'section_count' => $sectionCount, 'reference_count' => $referenceCount, 'primary_context_id' => $operationRun instanceof OperationRun ? (string) $operationRun->getKey() : (string) $tenant->getKey(), ], actor: $actor, status: 'success', resourceType: 'support_diagnostic_bundle', resourceId: $operationRun instanceof OperationRun ? 'operation_run:'.$operationRun->getKey() : 'tenant:'.$tenant->getKey(), targetLabel: $operationRun instanceof OperationRun ? 'Support diagnostics for operation #'.$operationRun->getKey() : 'Support diagnostics for '.$tenant->name, summary: $operationRun instanceof OperationRun ? 'Support diagnostics opened for operation #'.$operationRun->getKey() : 'Support diagnostics opened for '.$tenant->name, operationRunId: $operationRun instanceof OperationRun ? (int) $operationRun->getKey() : null, tenant: $tenant, ); } }