-
Notifications
You must be signed in to change notification settings - Fork 9
/
NonFungibleResourcesCollectionItem.swift
59 lines (50 loc) · 1.75 KB
/
NonFungibleResourcesCollectionItem.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
@available(*, deprecated, renamed: "GatewayAPI.FungibleResourcesCollectionItem")
typealias NonFungibleResourcesCollectionItem = GatewayAPI.FungibleResourcesCollectionItem
// MARK: - GatewayAPI.NonFungibleResourcesCollectionItem
extension GatewayAPI {
enum NonFungibleResourcesCollectionItem: Codable, Hashable {
case globallyAggregated(NonFungibleResourcesCollectionItemGloballyAggregated)
case vaultAggregated(NonFungibleResourcesCollectionItemVaultAggregated)
private enum CodingKeys: String, CodingKey {
case aggregationLevel = "aggregation_level"
}
var global: NonFungibleResourcesCollectionItemGloballyAggregated? {
if case let .globallyAggregated(wrapped) = self {
return wrapped
}
return nil
}
var vault: NonFungibleResourcesCollectionItemVaultAggregated? {
if case let .vaultAggregated(wrapped) = self {
return wrapped
}
return nil
}
var resourceAddress: String {
switch self {
case let .globallyAggregated(wrapped):
wrapped.resourceAddress
case let .vaultAggregated(wrapped):
wrapped.resourceAddress
}
}
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let aggregationLevel = try container.decode(ResourceAggregationLevel.self, forKey: .aggregationLevel)
switch aggregationLevel {
case .global:
self = try .globallyAggregated(NonFungibleResourcesCollectionItemGloballyAggregated(from: decoder))
case .vault:
self = try .vaultAggregated(NonFungibleResourcesCollectionItemVaultAggregated(from: decoder))
}
}
func encode(to encoder: Encoder) throws {
switch self {
case let .globallyAggregated(item):
try item.encode(to: encoder)
case let .vaultAggregated(item):
try item.encode(to: encoder)
}
}
}
}