import Foundation /// One turn of a sub-chat: a task's thread ("Talk about this"). public struct ThreadTurn: Identifiable, Sendable, Equatable { public var id: String public var who: Specialist? // nil is you /// Someone else on the team, by address; nil for you and for Equipo. public var person: String? public var text: String public var time: Date? /// Yours and still on its way: how it is going. nil once the server has it. public var delivery: EquipoSession.Outgoing.State? public var own: Bool { who == nil && person == nil } public var timeText: String { time.map { $0.formatted(date: .omitted, time: .shortened) } ?? "" } public init(id: String, who: Specialist?, person: String? = nil, text: String, time: Date?, delivery: EquipoSession.Outgoing.State? = nil) { self.id = id; self.who = who; self.person = person; self.text = text; self.time = time; self.delivery = delivery } /// A reply this device is still sending. public init(_ outgoing: EquipoSession.Outgoing) { self.init(id: outgoing.id, who: nil, text: outgoing.text, time: nil, delivery: outgoing.state) } /// A thread entry: yours, Equipo's own update (author "equipo"), or a teammate's. public init(_ entry: ThreadEntry, me: String?) { if entry.author == "equipo" { self.init(id: entry.id, who: .coordinator, text: entry.text, time: entry.at) } else if let me, entry.author.caseInsensitiveCompare(me) == .orderedSame { self.init(id: entry.id, who: nil, text: entry.text, time: entry.at) } else { self.init(id: entry.id, who: nil, person: entry.author, text: entry.text, time: entry.at) } } }