// SEND, AS THE CORE ANSWERS IT (`crates/cotton-ffi/src/phone/cotton_send.rs`):// a copy of a record to one of the person's people. The object decides what// goes, to whom, what fits and what is held; the core says every word a// send's card and tier show (`shows`, the Send step). These are the shapes,// and nothing here decides anything.importCottonKitimportCottonValuesimportFoundation/// A record a send names: what it landed as, or what the person already holds.publicstructSendRecordRef: Codable, Equatable, Hashable, Sendable {publicvar table: Stringpublicvar id: String}/// What `send.trust` is asked: a person by number, and whether every send from them is kept.publicstructSendTrust: Codable, Equatable, Hashable, Sendable {publicvar number: Stringpublicvar trusted: Bool}/// One act a send's card offers under it, or a person's row holds, in the/// core's order and words: Keep (with its size), Decline, Open, Remove,/// Undo, Always keep from {name}.publicstructSendAct: Decodable, Equatable, Hashable, Sendable, Identifiable {publicvar id: Stringpublicvar words: Stringpublicvar primary: Bool?publicvar red: Bool?/// Open's record.publicvar opens: SendRecordRef?/// The trust act's ask.publicvar trust: SendTrust?}/// How far a copy has come, in bytes.publicstructSendProgress: Decodable, Equatable, Hashable, Sendable {publicvar done: Double?publicvar bytes: Double?/// Done over the whole, 0…1; nil while the whole is not known.publicvar fraction: Double? {guardlet bytes, bytes > 0else { returnnil }return min(1, max(0, (done ?? 0) / bytes)) }}/// What a send's card says under it (`cotton_send::shows`).publicstructSendShows: Decodable, Equatable, Hashable, Sendable {/// "From {name}", on a received card.publicvar from: String?/// Its state in words: Kept, Already in your Cotton, Copying 3 MB of 12 MB, Delivered.publicvar line: String?publicvar progress: SendProgress?publicvar acts: [SendAct] = []}/// One send, received or made, as the inbox (or its thread item) holds it.publicstructSendItem: Decodable, Equatable, Identifiable, Sendable {publicvar id: Stringpublicvar state: String?publicvar title: String?/// The real card: the root table's face and its fields (`{face, fields}`).publicvar card: JSONValue?publicvar shows: SendShows?/// Whether its copy is still under way: the inbox is asked again until it lands.publicvar copying: Bool { state == "keeping" }}/// `send.inbox`'s answer.publicstructSendInbox: Decodable, Sendable {publicvar `in`: [SendItem]publicvar out: [SendItem]}/// One person of the Send tier (`shell.opened {step: send}`).publicstructSendPerson: Decodable, Equatable, Hashable, Sendable {/// Their Cotton thread: what `send.make` is asked with.publicvar value: Stringpublicvar words: Stringpublicvar number: Stringpublicvar trusted: Bool?publicvar initials: String?/// The size that goes, and whether every send from them is kept.publicvar detail: String?/// What a hold on them offers (Always keep from {name}); none while they wait.publicvar holds: [SendAct] = []/// Added by number and not yet added back: nothing goes to them, and a/// tap only says `detail` ("They have not added you yet").publicvar waiting: Bool?publicinit(from decoder: any Decoder) throws {let row = try decoder.container(keyedBy: CodingKeys.self) value = try row.decode(String.self, forKey: .value) words = try row.decode(String.self, forKey: .words) number = try row.decode(String.self, forKey: .number) trusted = try row.decodeIfPresent(Bool.self, forKey: .trusted) initials = try row.decodeIfPresent(String.self, forKey: .initials) detail = try row.decodeIfPresent(String.self, forKey: .detail) holds = try row.decodeIfPresent([SendAct].self, forKey: .holds) ?? [] waiting = try row.decodeIfPresent(Bool.self, forKey: .waiting) }privateenumCodingKeys: String, CodingKey {case value, words, number, trusted, initials, detail, holds, waiting }}/// Add a person: their number in the shell's one short-text input, as the/// core's `ask` names it (`shell.input {op: ask, kind: people_add}`), the one/// add Send's tier and Account's Your people both open.publicstructSendAdd: Decodable, Equatable, Hashable, Sendable {publicvar words: Stringpublicvar hint: String?/// The input's ask as the core wrote it, handed back to it whole.publicvar ask: JSONValue?}/// The door to Cotton chat's request, where the app keeps chat.publicstructSendDoor: Decodable, Equatable, Hashable, Sendable {publicvar words: Stringpublicvar path: String}/// What the tier says with nobody to send to.publicstructSendEmpty: Decodable, Equatable, Hashable, Sendable {publicvar words: Stringpublicvar door: SendDoor?}/// The Send step: the people, what goes and its size, Add a person, or why nobody can be sent to.publicstructSendStep: Decodable, Equatable, Hashable, Sendable {publicvar says: String?publicvar rows: [SendPerson] = []publicvar empty: SendEmpty?/// Add a person: present whenever the record can be sent, drawn last.publicvar add: SendAdd?/// The object's words for a record that cannot be sent.publicvar refused: String?}structSendStepAnswer: Decodable {var step: SendStep}/// The receipt Send leaves: "Sent {title} to {name}", its Undo, and what Undo says.publicstructSendReceipt: Decodable, Equatable, Sendable {publicvar words: Stringpublicvar undo: String?publicvar undone: String?}/// `send.make`'s answer.structSendMade: Decodable {var id: Stringvar receipt: SendReceipt?}/// `send.keep` / `send.undo`'s answer: the card's words as it now stands.structSendMoved: Decodable {var state: String?var shows: SendShows?}/// A Cotton thread's row that is a send: its `meta.cotton.send`, the item/// `send.inbox` or `send.make` kept on it.enumSendRow {staticfunc item(of message: TableRecord) -> SendItem? {guardlet send = CottonPictures.meta(of: message)?["cotton"]?["send"], let data = try? JSONEncoder().encode(send) else { returnnil }returntry? JSONDecoder().decode(SendItem.self, from: data) }}