Files
Gas-Tank-AR-App/GasTankAR/Services/StubDocuframeService.swift
2026-09-02 20:54:36 +02:00

45 lines
1.9 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// 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
}
}
}