fromWire static method

Implementation

static ZorphyBoundaryResult<AgentSessionDocumentPatch> fromWire(
  Map<String, Object?> raw,
) {
  final violations = <FieldViolation>[];
  final ops = ZorphyPatchWire.opsOf(raw, '', violations);
  final prefix = ZorphyPatchWire.opsPathOf(raw);
  PatchValue<String>? idValue;
  if (ops != null && ops.containsKey('id')) {
    final Object? rawValue = ZorphyPatchWire.fieldValue(
      ops['id'],
      '$prefix/id',
      violations,
    );
    idValue = (() {
      final idDecoded = ZorphyPatchWire.as<String>(
        rawValue,
        '$prefix/id',
        violations,
      );
      return idDecoded == null ? null : PatchValue<String>.set(idDecoded);
    })();
  }
  PatchValue<AgentSessionStatus>? statusValue;
  if (ops != null && ops.containsKey('status')) {
    final Object? rawValue = ZorphyPatchWire.fieldValue(
      ops['status'],
      '$prefix/status',
      violations,
    );
    statusValue = (() {
      final statusDecoded = ZorphyPatchWire.as<AgentSessionStatus>(
        rawValue,
        '$prefix/status',
        violations,
      );
      return statusDecoded == null
          ? null
          : PatchValue<AgentSessionStatus>.set(statusDecoded);
    })();
  }
  PatchValue<List<AgentMessage>?>? messagesValue;
  if (ops != null && ops.containsKey('messages')) {
    final Object? rawValue = ZorphyPatchWire.fieldValue(
      ops['messages'],
      '$prefix/messages',
      violations,
    );
    messagesValue = (() {
      if (rawValue == null) return PatchValue<List<AgentMessage>?>.set(null);
      final messagesDecoded = ZorphyPatchWire.listValue<AgentMessage>(
        rawValue,
        '$prefix/messages',
        violations,
        (element, elementPath, violations) =>
            ZorphyPatchWire.as<AgentMessage>(
              element,
              elementPath,
              violations,
            ),
      );
      return messagesDecoded == null
          ? null
          : PatchValue<List<AgentMessage>?>.set(messagesDecoded);
    })();
  }
  PatchValue<List<AgentToolCall>?>? toolCallsValue;
  if (ops != null && ops.containsKey('toolCalls')) {
    final Object? rawValue = ZorphyPatchWire.fieldValue(
      ops['toolCalls'],
      '$prefix/toolCalls',
      violations,
    );
    toolCallsValue = (() {
      if (rawValue == null) return PatchValue<List<AgentToolCall>?>.set(null);
      final toolCallsDecoded = ZorphyPatchWire.listValue<AgentToolCall>(
        rawValue,
        '$prefix/toolCalls',
        violations,
        (element, elementPath, violations) =>
            ZorphyPatchWire.as<AgentToolCall>(
              element,
              elementPath,
              violations,
            ),
      );
      return toolCallsDecoded == null
          ? null
          : PatchValue<List<AgentToolCall>?>.set(toolCallsDecoded);
    })();
  }
  PatchValue<String?>? activeToolValue;
  if (ops != null && ops.containsKey('activeTool')) {
    final Object? rawValue = ZorphyPatchWire.fieldValue(
      ops['activeTool'],
      '$prefix/activeTool',
      violations,
    );
    activeToolValue = (() {
      if (rawValue == null) return PatchValue<String?>.set(null);
      final activeToolDecoded = ZorphyPatchWire.as<String>(
        rawValue,
        '$prefix/activeTool',
        violations,
      );
      return activeToolDecoded == null
          ? null
          : PatchValue<String?>.set(activeToolDecoded);
    })();
  }
  PatchValue<int?>? turnsValue;
  if (ops != null && ops.containsKey('turns')) {
    final Object? rawValue = ZorphyPatchWire.fieldValue(
      ops['turns'],
      '$prefix/turns',
      violations,
    );
    turnsValue = (() {
      if (rawValue == null) return PatchValue<int?>.set(null);
      final turnsDecoded = ZorphyPatchWire.as<int>(
        rawValue,
        '$prefix/turns',
        violations,
      );
      return turnsDecoded == null ? null : PatchValue<int?>.set(turnsDecoded);
    })();
  }
  if (violations.isNotEmpty) {
    return BoundaryErr<AgentSessionDocumentPatch>(
      targetType: 'AgentSessionDocumentPatch',
      violations: violations,
    );
  }
  return BoundaryOk<AgentSessionDocumentPatch>(
    AgentSessionDocumentPatch(
      id: idValue ?? const PatchValue<String>.unchanged(),
      status: statusValue ?? const PatchValue<AgentSessionStatus>.unchanged(),
      messages:
          messagesValue ?? const PatchValue<List<AgentMessage>?>.unchanged(),
      toolCalls:
          toolCallsValue ??
          const PatchValue<List<AgentToolCall>?>.unchanged(),
      activeTool: activeToolValue ?? const PatchValue<String?>.unchanged(),
      turns: turnsValue ?? const PatchValue<int?>.unchanged(),
    ),
  );
}