2021-10-28 02:41:38 +05:30
|
|
|
import Defaults
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
struct AccountsBridge: Defaults.Bridge {
|
|
|
|
typealias Value = Account
|
|
|
|
typealias Serializable = [String: String]
|
|
|
|
|
|
|
|
func serialize(_ value: Value?) -> Serializable? {
|
2022-09-28 19:57:01 +05:30
|
|
|
guard let value else {
|
2021-10-28 02:41:38 +05:30
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
"id": value.id,
|
2022-07-02 02:58:32 +05:30
|
|
|
"instanceID": value.instanceID ?? "",
|
2023-04-22 18:38:33 +05:30
|
|
|
"name": value.name,
|
2022-12-09 05:45:19 +05:30
|
|
|
"apiURL": value.urlString,
|
2021-11-15 04:36:01 +05:30
|
|
|
"username": value.username,
|
|
|
|
"password": value.password ?? ""
|
2021-10-28 02:41:38 +05:30
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
func deserialize(_ object: Serializable?) -> Value? {
|
|
|
|
guard
|
2022-09-28 19:57:01 +05:30
|
|
|
let object,
|
2021-10-28 02:41:38 +05:30
|
|
|
let id = object["id"],
|
|
|
|
let instanceID = object["instanceID"],
|
|
|
|
let url = object["apiURL"],
|
2021-11-15 04:36:01 +05:30
|
|
|
let username = object["username"]
|
2021-10-28 02:41:38 +05:30
|
|
|
else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
let name = object["name"] ?? ""
|
2021-11-15 04:36:01 +05:30
|
|
|
let password = object["password"]
|
2021-10-28 02:41:38 +05:30
|
|
|
|
2022-12-09 05:45:19 +05:30
|
|
|
return Account(id: id, instanceID: instanceID, name: name, urlString: url, username: username, password: password)
|
2021-10-28 02:41:38 +05:30
|
|
|
}
|
|
|
|
}
|