import Foundation /// Der Bereich `zuschauer` (sicht/ANSICHT.md): was der Laeufer sieht und täte, ohne Klick. public struct Zuschauer: Decodable, Equatable, Sendable { public var laeuft: Bool public var leer: String? public var tische: [ZuschauerPlatz] = [] public var abgleich: [ZuschauerAbgleich] = [] enum CodingKeys: String, CodingKey { case laeuft, leer, tische, abgleich } public init(from d: Decoder) throws { let c = try d.container(keyedBy: CodingKeys.self) laeuft = c.wahr(.laeuft); leer = c.text(.leer); tische = c.objekte(.tische); abgleich = c.objekte(.abgleich) } } /// Ein offener Tisch: sein Stand und, solange die Hand läuft, der eigene Zug daran. public struct ZuschauerPlatz: Decodable, Equatable, Sendable, Identifiable { public var raum: String public var tisch: ZuschauerTisch? public var zug: ZuschauerZug? public var id: String { raum } enum CodingKeys: String, CodingKey { case raum, tisch, zug } public init(from d: Decoder) throws { let c = try d.container(keyedBy: CodingKeys.self) raum = c.text(.raum) ?? "?" tisch = (try? c.decodeIfPresent(ZuschauerTisch.self, forKey: .tisch)) ?? nil zug = (try? c.decodeIfPresent(ZuschauerZug.self, forKey: .zug)) ?? nil } } public struct ZuschauerZug: Decodable, Equatable, Sendable { public struct Empfehlung: Decodable, Equatable, Sendable { public var aktion: String? public var betragBB: Double? public var grund: String? public var klartext: String? public var confidence: Double? enum CodingKeys: String, CodingKey { case aktion, grund, klartext, confidence, betragBB = "betrag_bb" } public init(from d: Decoder) throws { let c = try d.container(keyedBy: CodingKeys.self) aktion = c.text(.aktion); betragBB = c.zahl(.betragBB); grund = c.text(.grund) klartext = c.text(.klartext); confidence = c.zahl(.confidence) } } public struct Linie: Decodable, Equatable, Sendable, Identifiable { public var aktion: String? public var betragBB: Double? public var evBB: Double? public var id: String { "\(aktion ?? "?")|\(betragBB ?? -1)" } enum CodingKeys: String, CodingKey { case aktion, betragBB = "betrag_bb", evBB = "ev_bb" } public init(from d: Decoder) throws { let c = try d.container(keyedBy: CodingKeys.self) aktion = c.text(.aktion); betragBB = c.zahl(.betragBB); evBB = c.zahl(.evBB) } } public struct Read: Decodable, Equatable, Sendable, Identifiable { public var sitz: Int public var einschaetzung: Spieler.Einschaetzung public var id: Int { sitz } enum CodingKeys: String, CodingKey { case sitz } public init(from d: Decoder) throws { let c = try d.container(keyedBy: CodingKeys.self) sitz = c.zahl(.sitz).map { Int($0) } ?? 0 einschaetzung = try Spieler.Einschaetzung(from: d) } } public var raum: String? public var hand: String? public var modus: String? public var strasse: String? public var karten: [String] = [] public var board: [String] = [] public var topfBB: Double? public var zuZahlenBB: Double? public var stackBB: Double? public var taktS: Double? public var hinweis: String? public var empfehlung: Empfehlung? public var equity: Double? public var linien: [Linie] = [] public var reads: [Read] = [] enum CodingKeys: String, CodingKey { case raum, hand, modus, strasse, karten, board, hinweis, empfehlung, equity, reads case topfBB = "topf_bb", zuZahlenBB = "zu_zahlen_bb", stackBB = "stack_bb", taktS = "takt_s", linien = "evs_bb" } public init(from d: Decoder) throws { let c = try d.container(keyedBy: CodingKeys.self) raum = c.text(.raum); hand = c.text(.hand); modus = c.text(.modus); strasse = c.text(.strasse) karten = c.liste(.karten); board = c.liste(.board); topfBB = c.zahl(.topfBB); zuZahlenBB = c.zahl(.zuZahlenBB) stackBB = c.zahl(.stackBB); taktS = c.zahl(.taktS); hinweis = c.text(.hinweis) empfehlung = (try? c.decodeIfPresent(Empfehlung.self, forKey: .empfehlung)) ?? nil equity = c.zahl(.equity); linien = c.objekte(.linien); reads = c.objekte(.reads) } } /// Der Tisch, auch ohne eigenen Platz: dieselben Felder wie sitzen.tisch, dazu wer dran ist. public struct ZuschauerTisch: Decodable, Equatable, Sendable { public struct AmZug: Decodable, Equatable, Sendable { public var name: String? public var fristS: Double? enum CodingKeys: String, CodingKey { case name, fristS = "frist_s" } public init(from d: Decoder) throws { let c = try d.container(keyedBy: CodingKeys.self) name = c.text(.name); fristS = c.zahl(.fristS) } } public var raum: String? public var modus: String? public var board: [String] = [] /// In Chips, wie der Tisch ihn zeigt (game.potInfo); fehlt, solange die Hand keinen meldet. public var topf: Double? public var amZug: AmZug? public var hinweis: String? public var tisch: TischAnsicht enum CodingKeys: String, CodingKey { case raum, modus, board, topf, hinweis, amZug = "am_zug" } public init(from d: Decoder) throws { let c = try d.container(keyedBy: CodingKeys.self) raum = c.text(.raum); modus = c.text(.modus); board = c.liste(.board); topf = c.zahl(.topf); hinweis = c.text(.hinweis) amZug = (try? c.decodeIfPresent(AmZug.self, forKey: .amZug)) ?? nil tisch = try TischAnsicht(from: d) } } public struct ZuschauerAbgleich: Decodable, Equatable, Sendable, Identifiable { public struct Zug: Decodable, Equatable, Sendable, Identifiable { public var strasse: String? public var bediener: String? public var kern: String? public var abweichung: Bool public var kostenBB: Double? public var warum: String? public var id: String { "\(strasse ?? "")|\(bediener ?? "")|\(kern ?? "")" } private struct Linie: Decodable { var aktion: String? } enum CodingKeys: String, CodingKey { case strasse, bediener, kern, abweichung, warum, kostenBB = "kosten_bb" } public init(from d: Decoder) throws { let c = try d.container(keyedBy: CodingKeys.self) strasse = c.text(.strasse); abweichung = c.wahr(.abweichung); kostenBB = c.zahl(.kostenBB); warum = c.text(.warum) bediener = ((try? c.decodeIfPresent(Linie.self, forKey: .bediener)) ?? nil)?.aktion kern = ((try? c.decodeIfPresent(Linie.self, forKey: .kern)) ?? nil)?.aktion } } public var raum: String? public var hand: String? public var abweichungen: Int public var kostenBB: Double? public var unbewertet: Int public var zuege: [Zug] = [] public var id: String { "\(raum ?? "")|\(hand ?? "")|\(zuege.count)|\(zuege.first?.id ?? "")" } enum CodingKeys: String, CodingKey { case raum, hand, abweichungen, unbewertet, zuege, kostenBB = "kosten_bb" } public init(from d: Decoder) throws { let c = try d.container(keyedBy: CodingKeys.self) raum = c.text(.raum); hand = c.text(.hand); abweichungen = c.zahl(.abweichungen).map { Int($0) } ?? 0 kostenBB = c.zahl(.kostenBB); unbewertet = c.zahl(.unbewertet).map { Int($0) } ?? 0; zuege = c.objekte(.zuege) } }