CockpitStepRecord.fromJson constructor

CockpitStepRecord.fromJson(
  1. Map<String, Object?> json
)

Implementation

factory CockpitStepRecord.fromJson(Map<String, Object?> json) {
  final actionArgs = Map<String, Object?>.from(
    (json['actionArgs'] as Map<Object?, Object?>?) ??
        const <Object?, Object?>{},
  );
  final artifactRefs =
      (json['artifactRefs'] as List<Object?>? ?? const <Object?>[])
          .cast<Map<Object?, Object?>>()
          .map(
            (item) =>
                CockpitArtifactRef.fromJson(Map<String, Object?>.from(item)),
          )
          .toList();
  final observationJson = json['observation'] as Map<Object?, Object?>?;
  final snapshotJson = json['snapshot'] as Map<Object?, Object?>?;
  final locatorJson = json['locator'] as Map<Object?, Object?>?;
  final locatorResolutionJson =
      json['locatorResolution'] as Map<Object?, Object?>?;
  final commandErrorJson = json['commandError'] as Map<Object?, Object?>?;
  final captureRefs =
      (json['captureRefs'] as List<Object?>? ?? const <Object?>[])
          .cast<Map<Object?, Object?>>()
          .map(
            (item) =>
                CockpitArtifactRef.fromJson(Map<String, Object?>.from(item)),
          )
          .toList();

  return CockpitStepRecord(
    index: json['index']! as int,
    actionType: json['actionType']! as String,
    actionArgs: actionArgs,
    observedAt: DateTime.parse(json['observedAt']! as String).toUtc(),
    observation: observationJson == null
        ? null
        : CockpitObservation.fromJson(
            Map<String, Object?>.from(observationJson),
          ),
    snapshot: snapshotJson == null
        ? null
        : CockpitSnapshot.fromJson(Map<String, Object?>.from(snapshotJson)),
    artifactRefs: artifactRefs,
    commandType: json['commandType'] == null
        ? null
        : CockpitCommandType.fromJson(json['commandType']),
    locator: locatorJson == null
        ? null
        : CockpitLocator.fromJson(Map<String, Object?>.from(locatorJson)),
    locatorResolution: locatorResolutionJson == null
        ? null
        : CockpitLocatorResolution.fromJson(
            Map<String, Object?>.from(locatorResolutionJson),
          ),
    commandError: commandErrorJson == null
        ? null
        : CockpitCommandError.fromJson(
            Map<String, Object?>.from(commandErrorJson),
          ),
    durationMs: json['durationMs'] as int?,
    status: json['status'] == null
        ? null
        : CockpitCommandStatus.fromJson(json['status']),
    targetKind: json['targetKind'] == null
        ? null
        : CockpitTargetKind.fromJson(json['targetKind']),
    executionPlane: json['executionPlane'] == null
        ? null
        : CockpitPlaneKind.fromJson(json['executionPlane']),
    surfaceKind: json['surfaceKind'] == null
        ? null
        : CockpitSurfaceKind.fromJson(json['surfaceKind']),
    fallbackTrail:
        (json['fallbackTrail'] as List<Object?>? ?? const <Object?>[])
            .map(CockpitPlaneKind.fromJson)
            .toList(growable: false),
    usedPlaneFallback: json['usedPlaneFallback'] as bool? ?? false,
    requestedCaptureProfile: json['requestedCaptureProfile'] == null
        ? null
        : CockpitCaptureProfile.fromJson(json['requestedCaptureProfile']),
    resolvedCaptureKind: json['resolvedCaptureKind'] == null
        ? null
        : CockpitCaptureKind.fromJson(json['resolvedCaptureKind']),
    usedCaptureFallback: json['usedCaptureFallback'] as bool? ?? false,
    degradationReason: json['degradationReason'] as String?,
    captureRefs: captureRefs,
  );
}