From 7aeba636f9910a1a47258781e973c75983fa2b49 Mon Sep 17 00:00:00 2001
From: Dariusz Rybicki <dariusz@elixxir.io>
Date: Fri, 29 Jul 2022 13:40:24 +0100
Subject: [PATCH] Update BackupReport model

---
 .../ElixxirDAppsSDK/Models/BackupReport.swift  | 18 ++++++++++++++++--
 .../Models/BackupReportTests.swift             |  9 +++++++--
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/Sources/ElixxirDAppsSDK/Models/BackupReport.swift b/Sources/ElixxirDAppsSDK/Models/BackupReport.swift
index 3ee3dca9..33b5b2e2 100644
--- a/Sources/ElixxirDAppsSDK/Models/BackupReport.swift
+++ b/Sources/ElixxirDAppsSDK/Models/BackupReport.swift
@@ -2,14 +2,14 @@ import Foundation
 
 public struct BackupReport: Equatable {
   public init(
-    ids: Data,
+    ids: [Data],
     params: Data
   ) {
     self.ids = ids
     self.params = params
   }
 
-  public var ids: Data
+  public var ids: [Data]
   public var params: Data
 }
 
@@ -26,4 +26,18 @@ extension BackupReport: Codable {
   public func encode() throws -> Data {
     try JSONEncoder().encode(self)
   }
+
+  public init(from decoder: Decoder) throws {
+    let container = try decoder.container(keyedBy: CodingKeys.self)
+    let idsData = try container.decode(Data.self, forKey: .ids)
+    ids = try JSONDecoder().decode([Data].self, from: idsData)
+    params = try container.decode(Data.self, forKey: .params)
+  }
+
+  public func encode(to encoder: Encoder) throws {
+    var container = encoder.container(keyedBy: CodingKeys.self)
+    let idsData = try JSONEncoder().encode(ids)
+    try container.encode(idsData, forKey: .ids)
+    try container.encode(params, forKey: .params)
+  }
 }
diff --git a/Tests/ElixxirDAppsSDKTests/Models/BackupReportTests.swift b/Tests/ElixxirDAppsSDKTests/Models/BackupReportTests.swift
index 93ef4f65..6eea0726 100644
--- a/Tests/ElixxirDAppsSDKTests/Models/BackupReportTests.swift
+++ b/Tests/ElixxirDAppsSDKTests/Models/BackupReportTests.swift
@@ -4,7 +4,12 @@ import XCTest
 
 final class BackupReportTests: XCTestCase {
   func testCoding() throws {
-    let idsB64 = "WyJPRHRRTTA4ZERpV3lXaE0wWUhjanRHWnZQcHRSa1JOZ1pHR2FkTG10dE9BRCJd"
+    let ids: [Data] = [
+      "id1".data(using: .utf8)!,
+      "id2".data(using: .utf8)!,
+      "id3".data(using: .utf8)!,
+    ]
+    let idsB64 = try JSONEncoder().encode(ids).base64EncodedString()
     let paramsB64 = "cGFyYW1z"
     let jsonString = """
     {
@@ -16,7 +21,7 @@ final class BackupReportTests: XCTestCase {
     let model = try BackupReport.decode(jsonData)
 
     XCTAssertNoDifference(model, BackupReport(
-      ids: Data(base64Encoded: idsB64)!,
+      ids: ids,
       params: Data(base64Encoded: paramsB64)!
     ))
 
-- 
GitLab