BasalProfileEntry.swift 933 B

1234567891011121314151617181920212223242526272829303132
  1. import Foundation
  2. struct BasalProfileEntry: JSON, Equatable, Identifiable {
  3. let id: String?
  4. let start: String
  5. let minutes: Int
  6. let rate: Decimal
  7. }
  8. protocol BasalProfileObserver {
  9. func basalProfileDidChange(_ basalProfile: [BasalProfileEntry])
  10. }
  11. extension BasalProfileEntry {
  12. private enum CodingKeys: String, CodingKey {
  13. case id = "_id"
  14. case start
  15. case minutes
  16. case rate
  17. }
  18. init(from decoder: Decoder) throws {
  19. let container = try decoder.container(keyedBy: CodingKeys.self)
  20. let id = try container.decode(String.self, forKey: .id)
  21. let start = try container.decode(String.self, forKey: .start)
  22. let minutes = try container.decode(Int.self, forKey: .minutes)
  23. let rate = try container.decode(Double.self, forKey: .rate).decimal ?? .zero
  24. self = BasalProfileEntry(id: id, start: start, minutes: minutes, rate: rate)
  25. }
  26. }