mirror of
https://github.com/appwrite/sdk-for-apple.git
synced 2026-11-18 20:53:33 +00:00
59 lines
1.6 KiB
Swift
59 lines
1.6 KiB
Swift
import Foundation
|
|
import JSONCodable
|
|
|
|
/// App scopes list
|
|
open class AppScopeList: Codable {
|
|
|
|
enum CodingKeys: String, CodingKey {
|
|
case total = "total"
|
|
case scopes = "scopes"
|
|
}
|
|
|
|
/// Total number of scopes that matched your query.
|
|
public let total: Int
|
|
/// List of scopes.
|
|
public let scopes: [AppScope]
|
|
|
|
init(
|
|
total: Int,
|
|
scopes: [AppScope]
|
|
) {
|
|
self.total = total
|
|
self.scopes = scopes
|
|
}
|
|
|
|
public required init(from decoder: Decoder) throws {
|
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
|
|
self.total = try container.contains(.total) ? container.decode(Int.self, forKey: .total) : 0
|
|
self.scopes = try container.contains(.scopes) ? container.decode([AppScope].self, forKey: .scopes) : []
|
|
}
|
|
|
|
public func encode(to encoder: Encoder) throws {
|
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
|
|
try container.encode(total, forKey: .total)
|
|
try container.encode(scopes, forKey: .scopes)
|
|
}
|
|
|
|
public func toMap() -> [String: Any] {
|
|
return [
|
|
"total": total as Any,
|
|
"scopes": scopes.map { $0.toMap() } as Any,
|
|
]
|
|
}
|
|
|
|
public static func from(map: [String: Any]) -> AppScopeList {
|
|
let defaults: [String: Any] = [
|
|
"total": 0,
|
|
"scopes": [Any](),
|
|
]
|
|
let map = defaults.merging(map) { _, new in new }
|
|
|
|
return AppScopeList(
|
|
total: map["total"] as! Int,
|
|
scopes: (map["scopes"] as! [[String: Any]]).map { AppScope.from(map: $0) }
|
|
)
|
|
}
|
|
}
|