Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : MacLustr SMS Gateway9// File : ios/MacLustrSMS/Core/Timeline.swift10// Description : Frise d'un envoi : étapes franchies, étape en cours,11// issue. Pure logique, testée.12// Module : ios13// Repository : https://git.spboucher.ai/maclustr-sms14// Project Website : https://sms.spboucher.ai15// Created : 2026-11-3016// Last Modified : 2026-12-0117//18// =============================================================================19// AUTHOR & PROFESSIONAL AFFILIATION20// =============================================================================21//22// Author : Simon-Pierre Boucher23// Position : Professor of Finance24// Institution : Université du Québec en Outaouais (UQO)25// Department : Département des sciences administratives26// Organization : SP Boucher27//28// Website : https://spboucher.ai29// Git : https://git.spboucher.ai30//31// =============================================================================32// OFFICIAL CONTACT DIRECTORY33// =============================================================================34//35// General : info@spboucher.ai36// Professional : contact@spboucher.ai37// Direct : simon@spboucher.ai38// Research : research@spboucher.ai39// Development : dev@spboucher.ai40// Support : support@spboucher.ai41// Security/Admin : admin@spboucher.ai42// Notifications : notifications@spboucher.ai43//44// Preferred Contact: admin@spboucher.ai45//46// =============================================================================47// COPYRIGHT & INTELLECTUAL PROPERTY48// =============================================================================49//50// Copyright (c) 202651// Simon-Pierre Boucher52//53// All rights reserved where applicable.54//55// This file is governed by the applicable project license,56// copyright notices, institutional agreements and relevant law.57//58// Unless expressly authorized by the applicable license or59// rights holder, copying, redistribution, sublicensing,60// publication and commercial exploitation are not permitted.61//62// Existing third-party rights and notices remain unaffected.63//64// =============================================================================65// CONFIDENTIALITY & SECURITY66// =============================================================================67//68// Classification : Public69// Distribution : Public repository; use is governed by the project license70// Security Contact : admin@spboucher.ai71//72// Access to this source does not independently grant permission73// to redistribute or disclose confidential materials.74//75// Do not embed credentials, private keys, access tokens,76// certificates or confidential personal information.77//78// =============================================================================79// LICENSE & MAINTENANCE80// =============================================================================81//82// License : None specified (no license file in this repository)83// Maintainer : Simon-Pierre Boucher84// Technical Contact: dev@spboucher.ai85//86// =============================================================================87// END OF SP BOUCHER SOURCE HEADER88// =============================================================================8990import Foundation9192struct TimelineStep: Equatable, Identifiable, Sendable {93 enum State: Sendable { case done, current, pending, skipped, problem }94 let status: MessageStatus95 let state: State96 let at: Date?97 var id: String { status.rawValue }98}99100enum SendTimeline {101 static let path: [MessageStatus] = [.queued, .dispatched, .accepted, .submitting, .submitted, .delivered]102103 /// Construit la frise à partir de l'état courant et du journal des transitions (les événements ignorés par le serveur ne comptent pas).104 static func steps(status: MessageStatus, events: [MessageEvent]) -> [TimelineStep] {105 var reached: [MessageStatus: Date] = [:]106 for e in events where !e.ignored { if let to = e.to.flatMap(MessageStatus.init(rawValue:)), reached[to] == nil { reached[to] = e.at } }107 let currentIndex = path.firstIndex(of: status)108 // Dernière étape du chemin nominal effectivement atteinte (utile quand l'issue est un échec ou une issue inconnue).109 let lastReached = path.lastIndex(where: { reached[$0] != nil }) ?? (status == .held ? -1 : 0)110 var steps: [TimelineStep] = []111 if status == .held || reached[.held] != nil {112 steps.append(TimelineStep(status: .held, state: status == .held ? .current : .done, at: reached[.held]))113 }114 for (i, s) in path.enumerated() {115 let state: TimelineStep.State116 if let c = currentIndex {117 // Une étape sautée (événement perdu puis rattrapé) reste marquée franchie : l'état courant la dépasse.118 // « remis au réseau » est une issue en soi : l'étape est franchie, pas « en cours ».119 state = i < c ? .done : i == c ? (s == .delivered || s == .submitted ? .done : .current) : .pending120 } else {121 state = i <= lastReached && status != .held ? .done : (status == .held ? .pending : .skipped)122 }123 steps.append(TimelineStep(status: s, state: state, at: reached[s]))124 }125 if currentIndex == nil, status != .held {126 steps.append(TimelineStep(status: status, state: .problem, at: reached[status]))127 }128 return steps129 }130 /// « Remis au réseau » est le succès habituel ; « livré » n'arrive que si l'opérateur renvoie un rapport.131 static func headline(_ status: MessageStatus) -> String {132 switch status {133 case .submitted: "Envoyé — remis au réseau"134 case .delivered: "Livré au destinataire"135 case .queued, .held: "En attente"136 case .dispatched, .accepted, .submitting: "Envoi en cours"137 case .failed: "Non envoyé"138 case .expired: "Expiré"139 case .cancelled: "Annulé"140 case .unknown: "Issue inconnue"141 case .received: "Reçu"142 }143 }144}145