45 lines
1.9 KiB
Swift
45 lines
1.9 KiB
Swift
//
|
||
// StubDocuframeService.swift
|
||
// GasTankAR
|
||
//
|
||
// Created by Dennis Nemec on 28.08.26.
|
||
//
|
||
|
||
import Foundation
|
||
import OSLog
|
||
|
||
/// Platzhalter-Implementierung des ``DocuframeService``. Simuliert Latenz und protokolliert
|
||
/// die Aufrufe, führt aber noch keinen echten Upload/Mailversand aus. Die konkrete
|
||
/// DOCUframe-Anbindung ersetzt diesen Stub später, ohne dass die Präsentationsschicht sich ändert.
|
||
struct StubDocuframeService: DocuframeService {
|
||
private static let logger = Logger(subsystem: "GasTankAR", category: "DOCUframe")
|
||
|
||
/// Optionaler HTTP-Statuscode, den der Stub simuliert. Bei 4xx/5xx wirft er den
|
||
/// entsprechenden ``DocuframeError`` – so lässt sich die Fehlerbehandlung durchspielen.
|
||
/// Standard `nil` = erfolgreicher Vorgang.
|
||
private let simulatedStatusCode: Int?
|
||
|
||
init(simulatedStatusCode: Int? = nil) {
|
||
self.simulatedStatusCode = simulatedStatusCode
|
||
}
|
||
|
||
func uploadPhotos(_ photos: [DocuframePhoto], projectLeadID: String) async throws {
|
||
try await simulate(operation: "Upload", photoCount: photos.count, projectLeadID: projectLeadID)
|
||
}
|
||
|
||
func sendEmail(_ photos: [DocuframePhoto], projectLeadID: String) async throws {
|
||
try await simulate(operation: "Mailversand", photoCount: photos.count, projectLeadID: projectLeadID)
|
||
}
|
||
|
||
private func simulate(operation: String, photoCount: Int, projectLeadID: String) async throws {
|
||
Self.logger.info("Stub-\(operation, privacy: .public) von \(photoCount) Foto(s) für Lead \(projectLeadID, privacy: .public)")
|
||
try await Task.sleep(for: .seconds(1))
|
||
|
||
// Simuliert eine Server-Antwort: Bei 4xx/5xx wird der passende Fehler geworfen.
|
||
if let simulatedStatusCode, let error = DocuframeError.from(statusCode: simulatedStatusCode) {
|
||
Self.logger.error("DOCUframe-\(operation, privacy: .public) fehlgeschlagen (HTTP \(simulatedStatusCode))")
|
||
throw error
|
||
}
|
||
}
|
||
}
|