// The pure words said about devices — by the Devices table's source, the join// request screen and Home's device line — and the ladder that decides WHICH// refusal they say.//// Three pure pieces, all of them tested as pure here://// • the platform's word and the actor's;// • one sentence per refusal code the pairing server names;// • the ladder that picks between the STANDING device refusal, the list's own// refusal, the code's sentence, and the last resort.//// **A refusal CODE is never smoothed.** A code nothing here names has no// sentence of its own and falls through to the refusal's own message, exactly// as `toastError` → `formatErrorForUser` does on the phone.importCottonKitimportFoundation/// The pairing digits: six of them, the server's own grammar.publiclet pairingDigits = 6/// The six, grouped the way a person reads them aloud: `482913` → `482 913`.////// A PURE function so the grouping is tested without a renderer, and the ONLY/// arithmetic done on the number. Anything that is not six ASCII numerals is/// drawn exactly as it arrived rather than reshaped — the server's answer is/// the authority, and a screen that tidied it could show a different number/// from the one it is asking about.publicfunc pairingDigitsGrouped(_ digits: String) -> String {guard digits.count == pairingDigits, digits.allSatisfy({ $0.isASCII && $0.isNumber }) else {return digits }let middle = digits.index(digits.startIndex, offsetBy: pairingDigits / 2)return"\(digits[digits.startIndex..<middle]) \(digits[middle...])"}/// Each of the six boxes, in order. Always six for a well-formed answer; an/// answer that is not six numerals fills none, and the row draws no question.publicfunc pairingDigitSlots(_ digits: String) -> [String] {guard digits.count == pairingDigits, digits.allSatisfy({ $0.isASCII && $0.isNumber }) else {return [] }return digits.map(String.init)}publicenumDeviceWords {/// The platform's word, from the wire's enum. `nil` for anything else, and/// the row then draws no platform at all rather than the raw enum value.publicstaticfunc platform(_ platform: String?) -> String? {switch platform {case"ios": return"iPhone"case"android": return"Android"case"mac": return"Mac"default: returnnil } }/// "by <name>" — who approved or removed a row, read off the list itself.////// `"self"` is the root row a server writes for itself at boot: nobody's/// phone. `"recovery-kit"` is the row a restore wrote for the Mac it made/// the server.staticfunc actor(_ deviceId: String?, in devices: [ApprovedDevice]) -> String {guardlet deviceId, !deviceId.isEmpty, deviceId != "self"else {returnShellLines.line("devices", "the_server") }if deviceId == "recovery-kit" {returnShellLines.line("devices", "the_recovery_kit") }iflet named = devices.first(where: { $0.deviceId == deviceId }) {return named.name }returnShellLines.line("devices", "another_device") }/// The detail line under a row's name: the platform and the version, joined/// by the middle dot, with either half absent when it is unknown.////// `[platform, appVersion].filter(Boolean).join(" · ")` — an EMPTY string is/// no line at all, which is what `detail ? … : null` means.publicstaticfunc detail(platform: String?, appVersion: String?) -> String? {let parts = [DeviceWords.platform(platform), appVersion] .compactMap { $0 } .filter { !$0.isEmpty }return parts.isEmpty ? nil : parts.joined(separator: " \u{00B7} ") }}/// One sentence per refusal, and the ladder above them.publicenumDeviceRefusalWords {publicstaticvar digitsMoved: String { ShellLines.line("devices", "that_request_changed_look") }/// What a pending row with no number is told, rather than approved.////// A server that predates the digits answers `null` on this field, and/// there is no question to put: the second factor IS seeing the same six on/// both screens, so an approve with nothing to compare would be an approve/// with no second factor at all.publicstaticlet noDigits =ShellLines.line("devices", "this_request_came_from")/// The pairing server's error-codes table, said in the person's words.////// `nil` for a code not named here — see the file header.publicstaticfunc sentence(forCode code: String?) -> String? {switch code {case"pairing_refused": returnShellLines.line("devices", "that_number_didn_t")case"pairing_not_found": returnShellLines.line("devices", "that_pairing_has_gone")case"pairing_ambiguous": returnShellLines.line("devices", "two_phones_are_waiting")case"rekey_needs_another_device": returnShellLines.line("devices", "approve_a_re_key")case"rekey_not_approved": returnShellLines.line("devices", "this_device_is_no")case"serving_twin": returnShellLines.line("devices", "this_mac_already_serves")case"device_last_full": returnShellLines.line("devices", "approve_another_device_first")case"bad_request": returnShellLines.line("devices", "that_device_s_code")default: returnnil } }/// The same, off whatever a `call` threw.publicstaticfunc sentence(for error: (any Error)?) -> String? {guardlet error else { returnnil }return sentence(forCode: OwnerRefusal.from(error)?.code) }/// What the devices card says when it cannot draw the list.////// **A read that failed is a sentence, not a skeleton** — a skeleton is/// only ever "loading" and it must have an end (2026-09-06: a 401 on every/// call left this card a skeleton for good). The list is the FILE's now/// (`read.devices`), so what can fail is the file, and the server's/// standing refusal of this phone is no longer an arm here: it is the/// banner over the whole app, and the rows stay readable under it. The/// order:////// 1. a refusal code the gate knows (`ServerRefusal.of`) — its title;/// 2. the code's own sentence;/// 3. the last resort.////// `nil` when there is no error — which is the card drawing rows or a/// skeleton.publicstaticfunc cardSentence(error: (any Error)?) -> String? {guardlet error else { returnnil }iflet code = OwnerRefusal.from(error)?.code,let refusal = ServerRefusal.of(code: code) {return refusal.title }iflet named = sentence(for: error) { return named }returnShellLines.line("devices", "couldn_t_read_your") }/// What a failed VERB says in the toast.////// The code's own sentence when there is one, else the refusal's own/// message (which is what `formatErrorForUser` surfaces), else the generic/// line.////// PORT GAP: [devices-refusal-not-reported] a refusal was once REPORTED as/// well as said (ruling R62). This app has no observability client and no/// HTTP client to report with, so/// only the SAYING half survives — every refusal a person reads on these two/// screens is invisible afterwards.publicstaticfunc toastSentence(for error: any Error) -> String {iflet named = sentence(for: error) { return named }return (error as? CottonCallError)?.message ?? CottonStrings.somethingWentWrong }}/// When a pairing asked, handwritten on its key tag: "asked 9:58 am" today,/// "asked Yesterday", then "asked Fri 2 Oct" — the core's `recent` part. A/// pairing with no stamp says nothing rather than "asked " alone.func pendingPairingAge(_ said: String?) -> String? {guardlet said, !said.isEmpty else { returnnil }return"asked \(said)"}