1
+ //
2
+ // Copyright (c) Microsoft Corporation. All rights reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ //
5
+
6
+ /**
7
+ Represents Event's properties.
8
+ */
9
+ public class EventProperties {
10
+ /// Event Name.
11
+ private var name : String
12
+ /// Event priority.
13
+ private var priority : ODWEventPriority = ODWEventPriority . unspecified
14
+ /// Event properties, Key being the name of the property and Value is property value.
15
+ private var _properties : [ String : Any ] = [ : ]
16
+ var properties : [ String : Any ] {
17
+ get {
18
+ return Dictionary ( uniqueKeysWithValues: _properties. lazy. map { ( $0, $1) } )
19
+ }
20
+ }
21
+ /// Event PII (Personal Identifiable Information) tags, Key being property name and Value is PIIKind value.
22
+ private var _piiTags : [ String : ODWPiiKind ] = [ : ]
23
+ var piiTags : [ String : ODWPiiKind ] {
24
+ get {
25
+ return Dictionary ( uniqueKeysWithValues: _piiTags. lazy. map { ( $0, $1) } )
26
+ }
27
+ }
28
+ /// Base type of an event.
29
+ private var eventType : String = String ( )
30
+
31
+ private func setPiiTag( _ name: String , withPiiKind piiKind: ODWPiiKind ) {
32
+ self . _piiTags [ name] = piiKind
33
+ }
34
+
35
+ /**
36
+ Constructs EventProperties object with event name.
37
+
38
+ - Parameters:
39
+ - name: Name of the event.
40
+ */
41
+ public init ( name: String ! ) {
42
+ self . name = name
43
+ }
44
+
45
+ /**
46
+ Constructs EventProperties object with event name and initial properties.
47
+
48
+ - Parameters:
49
+ - name: Name of the event.
50
+ - properties: Initial properties dictionary.
51
+ */
52
+ public init ( name: String ! , properties: [ String : Any ] ! ) {
53
+ self . name = name
54
+ self . _properties = properties
55
+ }
56
+
57
+ /**
58
+ Constructs EventProperties object with event name, initial properties and PII tags.
59
+
60
+ - Parameters:
61
+ - name: Name of the event.
62
+ - properties: Initial properties dictionary.
63
+ - piiTags: Initial PII tags.
64
+ */
65
+ public init ( name: String ! , withProperties properties: [ String : Any ] ! , withPiiTags piiTags: [ String : ODWPiiKind ] ! ) {
66
+ self . name = name
67
+ self . _properties = properties
68
+ self . _piiTags = piiTags
69
+ self . priority = . unspecified
70
+ }
71
+
72
+ /**
73
+ Sets the base type of the event, populated in Records.Type.
74
+
75
+ - Parameters:
76
+ - type: Type of the event.
77
+ */
78
+ public func setType( _ type: String ) {
79
+ self . eventType = type
80
+ }
81
+
82
+ /**
83
+ Sets a string property for an event.
84
+
85
+ - Parameters:
86
+ - name: Name of the property
87
+ - value: Value of the property.
88
+ */
89
+ public func setProperty( _ name: String , withValue value: Any ) {
90
+ self . _properties [ name] = value
91
+ }
92
+
93
+ /**
94
+ Sets a property for an event with PII tags.
95
+
96
+ - Parameters:
97
+ - name: Name of the property.
98
+ - value: Value of the property.
99
+ - piiKind: The kind of Personal Identifieable Information (PII), one from the ::ODWPiiKind enum values.
100
+ */
101
+ public func setProperty( _ name: String , withValue value: Any , withPiiKind piiKind: ODWPiiKind ) {
102
+ self . setProperty ( name, withValue: value)
103
+ self . setPiiTag ( name, withPiiKind: piiKind)
104
+ }
105
+
106
+ /**
107
+ Sets a double property for an event.
108
+
109
+ - Parameters:
110
+ - name: Name of the property.
111
+ - value: A Double that contains the property value.
112
+ */
113
+ public func setProperty( _ name: String , withDoubleValue value: Double ) {
114
+ self . _properties [ name] = value
115
+ }
116
+
117
+ /**
118
+ Sets a double property for an event with PiiTags.
119
+
120
+ - Parameters:
121
+ - name: Name of the property.
122
+ - value: A Double that contains the property value.
123
+ - piiKind: The kind of Personal Identifieable Information (PII), one from the ::ODWPiiKind enum values.
124
+ */
125
+ public func setProperty( _ name: String , withDoubleValue value: Double , withPiiKind piiKind: ODWPiiKind ) {
126
+ self . setProperty ( name, withDoubleValue: value)
127
+ self . setPiiTag ( name, withPiiKind: piiKind)
128
+ }
129
+
130
+ /**
131
+ Sets an integer property value for an event.
132
+
133
+ - Parameters:
134
+ - name: Name of the property.
135
+ - value: An integer that contains the property value.
136
+ */
137
+ public func setProperty( _ name: String , withInt64Value value: Int64 ) {
138
+ self . _properties [ name] = value
139
+ }
140
+
141
+ /**
142
+ Sets an integer property value for an event with PiiTags.
143
+
144
+ - Parameters:
145
+ - name: Name of the property.
146
+ - value: An integer that contains the property value.
147
+ - piiKind: The kind of Personal Identifieable Information (PII), one from the ::ODWPiiKind enum values.
148
+ */
149
+ public func setProperty( _ name: String , withInt64Value value: Int64 , withPiiKind piiKind: ODWPiiKind ) {
150
+ self . setProperty ( name, withInt64Value: value)
151
+ self . setPiiTag ( name, withPiiKind: piiKind)
152
+ }
153
+
154
+ /**
155
+ Sets an integer property value for an event.
156
+
157
+ - Parameters:
158
+ - name: Name of the property.
159
+ - value: An integer that contains the property value.
160
+ */
161
+ public func setProperty( _ name: String , withUInt8Value value: UInt8 ) {
162
+ self . _properties [ name] = value
163
+ }
164
+
165
+ /**
166
+ Sets an integer property value for an event with PiiTags.
167
+
168
+ - Parameters:
169
+ - name: Name of the property.
170
+ - value: An integer that contains the property value.
171
+ - piiKind: The kind of Personal Identifieable Information (PII), one from the ::ODWPiiKind enum values.
172
+ */
173
+ public func setProperty( _ name: String , withUInt8Value value: UInt8 , withPiiKind piiKind: ODWPiiKind ) {
174
+ self . setProperty ( name, withUInt8Value: value)
175
+ self . setPiiTag ( name, withPiiKind: piiKind)
176
+ }
177
+
178
+ /**
179
+ Sets an integer property value for an event.
180
+
181
+ - Parameters:
182
+ - name: Name of the property.
183
+ - value: An integer that contains the property value.
184
+ */
185
+ public func setProperty( _ name: String , withUInt64Value value: UInt64 ) {
186
+ self . _properties [ name] = value
187
+ }
188
+
189
+ /**
190
+ Sets an integer property value for an event with PiiTags.
191
+
192
+ - Parameters:
193
+ - name: Name of the property.
194
+ - value: An integer that contains the property value.
195
+ - piiKind: The kind of Personal Identifieable Information (PII), one from the ::ODWPiiKind enum values.
196
+ */
197
+ public func setProperty( _ name: String , withUInt64Value value: UInt64 , withPiiKind piiKind: ODWPiiKind ) {
198
+ self . setProperty ( name, withUInt64Value: value)
199
+ self . setPiiTag ( name, withPiiKind: piiKind)
200
+ }
201
+
202
+ /**
203
+ Sets a Bool property value for an event.
204
+
205
+ - Parameters:
206
+ - name: Name of the property.
207
+ - value: A Bool that contains the property value.
208
+ */
209
+ public func setProperty( _ name: String , withBoolValue value: Bool ) {
210
+ self . _properties [ name] = value
211
+ }
212
+
213
+ /**
214
+ Sets a Bool property value along with PiiTags.
215
+
216
+ - Parameters:
217
+ - name: Name of the property.
218
+ - value: A Bool that contains the property value.
219
+ - piiKind: The kind of Personal Identifieable Information (PII), one from the ::ODWPiiKind enum values.
220
+ */
221
+ public func setProperty( _ name: String , withBoolValue value: Bool , withPiiKind piiKind: ODWPiiKind ) {
222
+ self . setProperty ( name, withBoolValue: value)
223
+ self . setPiiTag ( name, withPiiKind: piiKind)
224
+ }
225
+
226
+ /**
227
+ Sets a UUID property for an event.
228
+
229
+ - Parameters:
230
+ - name: Name of the property.
231
+ - value: A UUID that contains the property value.
232
+ */
233
+ public func setProperty( _ name: String , withUUIDValue value: UUID ) {
234
+ self . _properties [ name] = value
235
+ }
236
+
237
+ /**
238
+ Sets a UUID property for an event.
239
+
240
+ - Parameters:
241
+ - name: Name of the property.
242
+ - value: A UUID that contains the property value.
243
+ - piiKind: The kind of Personal Identifieable Information (PII), one from the ::ODWPiiKind enum values.
244
+ */
245
+ public func setProperty( _ name: String , withUUIDValue value: UUID , withPiiKind piiKind: ODWPiiKind ) {
246
+ self . setProperty ( name, withUUIDValue: value)
247
+ self . setPiiTag ( name, withPiiKind: piiKind)
248
+ }
249
+
250
+ /**
251
+ Sets a date property for an event.
252
+
253
+ - Parameters:
254
+ - name: Name of the property.
255
+ - value: A Date that contains the property value.
256
+ */
257
+ public func setProperty( _ name: String , withDateValue value: Date ) {
258
+ self . _properties [ name] = value
259
+ }
260
+
261
+ /**
262
+ Sets a date property for an event with PiiTags.
263
+
264
+ - Parameters:
265
+ - name: Name of the property.
266
+ - value: A Date that contains the property value.
267
+ - piiKind: The kind of Personal Identifieable Information (PII), one from the ::ODWPiiKind enum values.
268
+ */
269
+ public func setProperty( _ name: String , withDateValue value: Date , withPiiKind piiKind: ODWPiiKind ) {
270
+ self . setProperty ( name, withDateValue: value)
271
+ self . setPiiTag ( name, withPiiKind: piiKind)
272
+ }
273
+
274
+ /**
275
+ Sets privacy metadat for an event.
276
+
277
+ - Parameters:
278
+ - privTags: Privacy data type of the event.
279
+ - privLevel: Privacy diagnostic level of the event.
280
+ */
281
+ public func setPrivacyMetadata( _ privTags: ODWPrivacyDataType , withdWDiagLevel privLevel: ODWDiagLevel ) {
282
+ self . setProperty ( " EventInfo.PrivTags " , withUInt64Value: UInt64 ( privTags. rawValue) )
283
+ self . setProperty ( " EventInfo.Level " , withUInt8Value: UInt8 ( privLevel. rawValue) )
284
+ }
285
+ }
0 commit comments