Shared/Models/Context.swift (4972B)
1import Foundation
2
3
4
5
6
7
8struct Context: Codable, Hashable, Sendable {
9 var location: LocationContext?
10 var weather: WeatherContext?
11 var audio: AudioContext?
12 var motion: MotionContext?
13 var device: DeviceContext?
14 var photos: PhotosContext?
15}
16
17struct LocationContext: Codable, Hashable, Sendable {
18 var coordinate: Coordinate
19
20 var altitude: Double?
21
22 var horizontalAccuracy: Double?
23
24 var verticalAccuracy: Double?
25
26 var speed: Double?
27
28 var course: Double?
29
30 var timestamp: Date?
31
32 var placemark: Placemark?
33
34
35 var localisedPlacemarks: [Placemark]?
36}
37
38struct Placemark: Codable, Hashable, Sendable {
39 var name: String?
40 var subThoroughfare: String?
41 var thoroughfare: String?
42 var subLocality: String?
43 var locality: String?
44 var subAdministrativeArea: String?
45 var administrativeArea: String?
46 var postalCode: String?
47 var country: String?
48 var inlandWater: String?
49 var ocean: String?
50
51
52 var language: String?
53
54 var countryCode: String?
55
56 var cityWithContext: String?
57 var fullAddress: String?
58 var shortAddress: String?
59}
60
61extension Placemark {
62
63
64
65
66 var displayLocality: String? {
67 if let cityWithContext { return cityWithContext }
68 guard let locality else { return subLocality ?? name }
69 guard let administrativeArea, administrativeArea != locality else { return locality }
70 return "\(locality), \(administrativeArea)"
71 }
72}
73
74struct WeatherContext: Codable, Hashable, Sendable {
75 enum Source: String, Codable, Sendable {
76 case wunderground
77 case darkSky
78 case weatherKit
79 }
80
81 var source: Source
82
83
84 var backfilled: Bool?
85 var condition: String?
86
87 var temperature: Double?
88
89 var feelsLike: Double?
90
91 var dewPoint: Double?
92
93 var humidity: Double?
94
95 var pressure: Double?
96
97 var windSpeed: Double?
98
99 var windGust: Double?
100
101 var windDirection: Double?
102
103 var visibility: Double?
104 var uvIndex: Double?
105
106 var cloudCover: Double?
107
108 var precipitationChance: Double?
109
110 var precipitationToday: Double?
111}
112
113struct AudioContext: Codable, Hashable, Sendable {
114 enum Source: String, Codable, Sendable {
115 case microphone
116 case healthEnvironmental
117 }
118
119 var source: Source
120
121 var average: Double?
122 var peak: Double?
123}
124
125struct MotionContext: Codable, Hashable, Sendable {
126
127 var steps: Int?
128 var floorsAscended: Int?
129 var floorsDescended: Int?
130
131 var pressure: Double?
132
133 var relativeAltitude: Double?
134}
135
136struct DeviceContext: Codable, Hashable, Sendable {
137 enum BatteryState: String, Codable, Sendable {
138 case unplugged
139 case charging
140 case full
141 }
142
143 enum Connectivity: String, Codable, Sendable {
144 case wifi
145 case cellular
146 case none
147 }
148
149
150 var batteryLevel: Double?
151 var batteryState: BatteryState?
152 var connectivity: Connectivity?
153}
154
155struct PhotosContext: Codable, Hashable, Sendable {
156
157 var count: Int
158 var photos: [PhotoMetadata] = []
159}
160
161struct PhotoMetadata: Codable, Hashable, Sendable {
162 var date: Date?
163 var coordinate: Coordinate?
164 var pixelWidth: Int?
165 var pixelHeight: Int?
166 var make: String?
167 var model: String?
168}