// A record's card as the core resolved it (`cotton_core::records::card`,// under `@card`): the face kind, the corner's words, the pace band and plate,// and each place's value. The deck draws these and composes no words. The one// value a face takes; reading it off a record, and saying a card the deck// cannot read, is the app's (`CottonUI/Deck/DeckCard+Record.swift`).importFoundation/// The pace bands (`transforms::pace::Pace`), most pressing first.publicenumDeckPace: String, Sendable, CaseIterable {case late, soon, upcoming, someday, done}publicstructDeckCard: Equatable, Sendable {publicstaticlet key = "@card"publicvar face: Stringpublicvar corner: String?/// The corner's date is behind: the late ink.publicvar pressing: Boolpublicvar pace: DeckPace?/// The band's plate, 0..<8, when the card carries the pace art.publicvar plate: Int?/// The thread's recent messages, filled by the core before presentation.publicvar thread: ThreadHistory?publicvar fields: [String: RecordValue]// What the deck read for the card beyond the core's words// (`CardReadings.swift`; CottonUI's `DeckCardFill`). A card read off// `@card` holds none; a face draws the ones it is given./// Answered whole by the core (`shell.deck`): its readings are the/// core's, and nothing on the phone fills it again.publicvar answered = false/// The id of the record it is the card of: whose track it plays.publicvar record: String?/// The pages it turns to after its face (`card.pages`).publicvar pages: [CardPage] = []publicvar related: [CardRelatedCount] = []publicvar relatedReadFailed = false/// Its places and its table's columns under their labels.publicvar labels = CardLabels()/// The rating its facts name in the rating column, out of five.publicvar stars: Double?/// The value stored in the column under a place, by slot, as kept (a/// state's "running", a dish's kind), never its label.publicvar stored: [String: String] = [:]/// A delivery's states, as its columns hold them.publicvar delivery: KitchenDeliveryState?/// How a person is reached.publicvar reach = CardReach()/// The record's own file (`storage_path`): a document's first page.publicvar file: String?/// An album's print keys, in its order; nil until read.publicvar prints: [String]?/// `@card` as the core resolved it (`ResolvedCard`'s JSON): nil when/// absent, the typed failure when it is there and not in that shape.publicstaticfunc read(_ value: RecordValue) -> Result<DeckCard, DeckCardFailure>? {if value == .null { returnnil }guardcase .object(let card) = value else { return .failure(.notAnObject("card")) }guardcase .text(let face)? = card["face"], !face.isEmpty else { return .failure(.noFace) }var corner: String?switch card["corner"] {casenil, .null?: corner = nilcase .text(let words)?: corner = wordsdefault: return .failure(.notWords("corner")) }var pressing = falseswitch card["pressing"] {casenil, .null?: breakcase .bool(let value)?: pressing = valuedefault: return .failure(.notABool("pressing")) }var pace: DeckPace?switch card["pace"] {casenil, .null?: pace = nilcase .text(let band)?:guardlet known = DeckPace(rawValue: band) else { return .failure(.unknownPace(band)) } pace = knowndefault: return .failure(.notWords("pace")) }var plate: Int?switch card["plate"] {casenil, .null?: plate = nilcase .number(let number)?: plate = Int(number)default: return .failure(.notANumber("plate")) }var fields: [String: RecordValue] = [:]switch card["fields"] {casenil, .null?: breakcase .object(let given)?: fields = givendefault: return .failure(.notAnObject("fields")) }var resolved = DeckCard(face: face, corner: corner, pressing: pressing, pace: pace, plate: plate, fields: fields)iflet thread = card["thread"], thread != .null {do { resolved.thread = try JSONDecoder().decode(ThreadHistory.self, from: JSONEncoder().encode(thread)) }catch { return .failure(.invalidThread) } }return .success(resolved) }publicinit(face: String, corner: String?, pressing: Bool, pace: DeckPace?, plate: Int?, fields: [String: RecordValue]) {self.face = faceself.corner = cornerself.pressing = pressingself.pace = paceself.plate = plateself.fields = fields }/// A place's words, nil when the definition fills none or it is empty.publicfunc text(_ slot: String) -> String? {guardlet text = fields[slot]?.text, !text.isEmpty else { returnnil }return text }/// The check's state; nil when the face has no check.publicvar checked: Bool? {guardcase .bool(let checked)? = fields["check"] else { returnnil }return checked }}/// Why a record's `@card` could not be read: the core's card JSON/// (`cotton_core::records::card::ResolvedCard`) and this decoder disagree.publicenumDeckCardFailure: Error, Equatable, Sendable {case notAnObject(String)case invalidThreadcase noFacecase notWords(String)case notABool(String)case notANumber(String)case unknownPace(String)}publicstructCardRelatedCount: Equatable, Sendable, Identifiable {publicvar id: String/// The count as the core says it, in the related table's own words and/// the plural form its number calls for ("1 photo", "12 photos").publicvar said: Stringpublicvar count: Intpublicinit(id: String, said: String, count: Int) {self.id = id; self.said = said; self.count = count }}