2021-10-27 21:11:38 +00:00
|
|
|
import Defaults
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
struct AccountsBridge: Defaults.Bridge {
|
|
|
|
typealias Value = Account
|
|
|
|
typealias Serializable = [String: String]
|
|
|
|
|
|
|
|
func serialize(_ value: Value?) -> Serializable? {
|
2022-09-28 14:27:01 +00:00
|
|
|
guard let value else {
|
2021-10-27 21:11:38 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
"id": value.id,
|
2022-07-01 21:28:32 +00:00
|
|
|
"instanceID": value.instanceID ?? "",
|
2021-10-27 21:11:38 +00:00
|
|
|
"name": value.name ?? "",
|
2022-12-09 00:15:19 +00:00
|
|
|
"apiURL": value.urlString,
|
2021-11-14 23:06:01 +00:00
|
|
|
"username": value.username,
|
|
|
|
"password": value.password ?? ""
|
2021-10-27 21:11:38 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
func deserialize(_ object: Serializable?) -> Value? {
|
|
|
|
guard
|
2022-09-28 14:27:01 +00:00
|
|
|
let object,
|
2021-10-27 21:11:38 +00:00
|
|
|
let id = object["id"],
|
|
|
|
let instanceID = object["instanceID"],
|
|
|
|
let url = object["apiURL"],
|
2021-11-14 23:06:01 +00:00
|
|
|
let username = object["username"]
|
2021-10-27 21:11:38 +00:00
|
|
|
else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
let name = object["name"] ?? ""
|
2021-11-14 23:06:01 +00:00
|
|
|
let password = object["password"]
|
2021-10-27 21:11:38 +00:00
|
|
|
|
2022-12-09 00:15:19 +00:00
|
|
|
return Account(id: id, instanceID: instanceID, name: name, urlString: url, username: username, password: password)
|
2021-10-27 21:11:38 +00:00
|
|
|
}
|
|
|
|
}
|