import Foundation /// The PDF file-name scheme: /// /// Redline---.pdf /// Redline--.pdf (no lane recorded) /// /// * `yyyyMMdd-HHmm` is Dubai wall-clock time (the time the PDF was built) — the /// file sorts chronologically as plain text on every filesystem. /// * `LANE` is the upper-cased lane/environment, reduced to A–Z, 0–9 and single /// dashes ("OMS test lane" → "OMS-TEST-LANE") so the name is safe everywhere. /// * `SHORTID` is the session's 8-character id, which keeps two lanes in the same /// minute — and a re-send of the same session — distinguishable and unique. public enum PDFFileName { /// Lane token length cap so the whole name stays comfortably short. public static let laneMaxLength = 24 public static func laneSlug(_ lane: String) -> String { var slug = "" var pendingDash = false for character in lane.uppercased() { if character.isASCII, character.isLetter || character.isNumber { if pendingDash, !slug.isEmpty { slug.append("-") } slug.append(character) pendingDash = false } else { pendingDash = true } } let capped = String(slug.prefix(laneMaxLength)) return capped.hasSuffix("-") ? String(capped.dropLast()) : capped } public static func make(builtAt: Date, lane: String, sessionID: UUID) -> String { let shortID = String( sessionID.uuidString.replacingOccurrences(of: "-", with: "").prefix(8) ).uppercased() let slug = laneSlug(lane) var parts = ["Redline", DubaiTime.fileMinuteStamp(builtAt)] if !slug.isEmpty { parts.append(slug) } parts.append(shortID) return parts.joined(separator: "-") + ".pdf" } /// The session folder's own readable label, e.g. "DEV03-4F2A9C1D" — used in the /// UI only; the on-disk folder name stays the session UUID. public static func sessionLabel(lane: String, sessionID: UUID) -> String { let shortID = String( sessionID.uuidString.replacingOccurrences(of: "-", with: "").prefix(8) ).uppercased() let slug = laneSlug(lane) return slug.isEmpty ? shortID : "\(slug)-\(shortID)" } }