import Foundation /// One file of a snippet. `content` rides only on `snippet show`; a list /// row carries the name and size. nonisolated struct SnippetFile: Decodable, Sendable, Hashable, Identifiable { let name: String let size: Int let content: String? var id: String { name } } /// One row of `snippet list`, and the whole of `snippet show`. nonisolated struct Snippet: Decodable, Sendable, Hashable, Identifiable { let id: String let url: String? let owner: String /// Omitted by the server when empty. let description: String? /// public, unlisted or private. let visibility: String let createdAt: Date let updatedAt: Date let files: [SnippetFile] enum CodingKeys: String, CodingKey { case id, url, owner, description, visibility, files case createdAt = "created_at" case updatedAt = "updated_at" } /// The web titles a snippet by its description and falls back to /// the id. var title: String { if let description, !description.isEmpty { return description } return id } var fileNames: String { files.map(\.name).joined(separator: ", ") } }