// A DOOR THAT READS THE DEVICE (`create.doors[].reads`; Cotton Health, 13 Nov // 2026): Read Apple Health. What the door reads is the flavour's own, linked // only by the app that reads it (Cotton Health links HealthKit, no other app // does), so the shell names the act and the app attaches the reader at // launch (`CottonHealthKit`'s `HealthEngine`). A tap asks the system then and // there, through `SystemCapabilityAuthority`, and never before: an app that // asked at launch would ask a person who has not yet said what they came for. import CottonKit import SwiftUI /// What a reading door reads, attached by the app that links it. public protocol DeviceReading: Sendable { /// Read `reads` into the database the core has open and say how it went. func read(_ reads: DefinitionDeviceReads, core: any CottonCalling) async -> DeviceReadSaid } /// A reading door's one line: what came in, or why nothing did. public struct DeviceReadSaid: Equatable, Sendable { public let line: String public let failed: Bool public init(line: String, failed: Bool) { self.line = line self.failed = failed } } /// The reader this app attached, if it reads anything. @MainActor public enum DeviceReadings { public static var reader: (any DeviceReading)? /// The door's tap: the attached reader reads and its line is said. static func read(_ reads: DefinitionDeviceReads, core: (any CottonCalling)?, toasts: ToastCenter?) async { guard let reader, let core else { toasts?.show(ShellLines.line("cards", "health.read.unavailable"), tone: .error) return } let said = await reader.read(reads, core: core) toasts?.show(said.line, tone: said.failed ? .error : .success) } }