// A photo or file column's value: the attachment's ref, and a file's name. // What a column stores it as is the app's (`CottonUI/Editors/ColumnValues.swift`). import Foundation /// A photo or file column's value: a stored reference, and for a file the /// name it arrived with. public struct AttachmentValue: Equatable, Sendable { public var ref: String public var name: String? public init(ref: String, name: String?) { self.ref = ref self.name = name } public static func read(_ value: RecordValue) -> AttachmentValue? { switch value { case .text(let ref) where !ref.isEmpty: return AttachmentValue(ref: ref, name: nil) case .object(let fields): guard case .text(let ref)? = fields["ref"], !ref.isEmpty else { return nil } if case .text(let name)? = fields["name"] { return AttachmentValue(ref: ref, name: name) } return AttachmentValue(ref: ref, name: nil) default: return nil } } }