// What the deck reads for a card beyond the core's words (`DeckCard`'s// readings, filled by CottonUI's `DeckCardFill`): the pages it turns to, the// labels its places stand under, the songs a playlist pins, a delivery's states, the ways a person is reached. Plain// values, including the core's thread history, so a face draws from its card// alone and Loom from its specimens.importFoundation/// One page past a card's face: a column's long words under its label.publicstructCardPage: Equatable, Sendable {publiclet label: Stringpubliclet text: String/// The column keeps Markdown: its page is set, never typed with its marks.publicvar markdown = falsepublicinit(label: String, text: String, markdown: Bool = false) {self.label = labelself.text = textself.markdown = markdown }}/// Each place of a card under its column's label, as the package wrote it/// ("Address", "Due", "Price a plate"): the words a fact stands under.publicstructCardLabels: Equatable, Sendable {publicvar bySlot: [String: String] = [:]publicvar byColumn: [String: String] = [:]publicinit(bySlot: [String: String] = [:], byColumn: [String: String] = [:]) {self.bySlot = bySlotself.byColumn = byColumn }publicsubscript(slot slot: String) -> String? { bySlot[slot] }publicsubscript(column column: String) -> String? { byColumn[column] }}/// The numbers and addresses a person's card is reached by, as the record/// holds them, and the channel their thread runs on.publicstructCardReach: Equatable, Sendable {publicvar phones: [String] = []publicvar emails: [String] = []publicvar channel: String?/// The ways the app can reach them from these, as it worked them out/// (CottonUI's `ContactHandoff`): the discs the face draws.publicvar call = falsepublicvar message = falsepublicvar email = falsepublicinit(phones: [String] = [], emails: [String] = [], channel: String? = nil, call: Bool = false, message: Bool = false, email: Bool = false) {self.phones = phonesself.emails = emailsself.channel = channelself.call = callself.message = messageself.email = email }}/// What a thread's card says past its last message: how many messages there/// are since the first, in the core's words and the first one's year, and/// the few before the last.publicstructThreadHistory: Codable, Equatable, Sendable {publicstructLine: Codable, Equatable, Identifiable, Sendable {publiclet id: Stringpubliclet words: Stringpubliclet mine: Bool/// Present only when the card reader supplied these facts.publiclet time: String?publiclet sender: String?publicinit(id: String, words: String, mine: Bool, time: String? = nil, sender: String? = nil) {self.id = idself.words = wordsself.mine = mineself.time = timeself.sender = sender } }publicvar count: String?publicvar earlier: [Line] = []/// The last message with its direction and metadata, when supplied./// A card without local history may carry only its body preview.publicvar last: Line?publicinit(count: String? = nil, earlier: [Line] = [], last: Line? = nil) {self.count = countself.earlier = earlierself.last = last }}/// One song pinned on a playlist's J-card: its own cover, or, while it/// keeps none, its sleeve printed with its title and artist.publicenumMusicTile: Hashable, Sendable {case art(String)case sleeve(title: String?, artist: String?)}/// The words a music whole's faces join (an album's, a playlist's, a/// cassette's facts).publicenumMusicWhole {/// Words joined as the cards join them; nil when there are none.publicstaticfunc joined(_ words: [String?]) -> String? {let said = words.compactMap { $0 }.filter { !$0.isEmpty }return said.isEmpty ? nil : said.joined(separator: ShellLines.line("cards", "join")) }}/// The package's columns the kitchen's faces read state from.publicenumKitchenColumns {publicstaticlet delivered = "delivered"publicstaticlet paid = "paid"/// A delivery's plan: the customer's subscription it is a meal of.publicstaticlet plan = "subscription"publicstaticlet rating = "rating"}/// A delivery as its columns hold it: gone out or not, paid or not, and/// whether it is a meal on a plan.publicstructKitchenDeliveryState: Equatable, Sendable {publicvar delivered: Boolpublicvar paid: Boolpublicvar onPlan: Boolpublicinit(delivered: Bool, paid: Bool, onPlan: Bool) {self.delivered = deliveredself.paid = paidself.onPlan = onPlan }publicstaticfunc of(_ record: TableRecord) -> KitchenDeliveryState {KitchenDeliveryState( delivered: record[KitchenColumns.delivered].bool == true, paid: record[KitchenColumns.paid].bool == true, onPlan: holds(record[KitchenColumns.plan])) }/// The plan tag: the plan column's own label, while the delivery is a/// meal on one; nil off a plan.publicfunc planTag(_ labels: CardLabels) -> String? { onPlan ? labels[column: KitchenColumns.plan] : nil }/// The states stamped on the card, each its column's label, in order:/// Delivered, then Paid — only those its columns hold.publicfunc stamps(_ labels: CardLabels) -> [String] { [(delivered, KitchenColumns.delivered), (paid, KitchenColumns.paid)] .compactMap { held, column in held ? labels[column: column] : nil } }privatestaticfunc holds(_ value: RecordValue) -> Bool {switch value {case .null: falsecase .text(let text): !text.trimmingCharacters(in: .whitespaces).isEmptycase .list(let items): !items.isEmptycase .object(let fields): !fields.isEmptycase .number, .bool: true } }}