import 'cloud_reconciliation_service.dart'; import '../../database/database.dart'; import '../auth/auth_service.dart'; class CloudRestoreResult { final CloudReconciliationResult metadata; final int telemetryPending; const CloudRestoreResult({ required this.metadata, this.telemetryPending = 0, }); } /// Additive, resumable MotorCloud restore coordinator. /// /// Metadata is restored first. Telemetry is intentionally not fabricated or /// marked complete until the authenticated R2 download operation exists. /// Existing local rides are never deleted or overwritten. class CloudRestoreService { final AuthService _authService; final CloudReconciliationService _metadata; CloudRestoreService({ required AppDatabase db, required AuthService authService, CloudReconciliationService? metadata, }) : _authService = authService, _metadata = metadata ?? CloudReconciliationService(db: db, authService: authService); Future restore() async { final user = _authService.currentUser; if (user == null || user.isAnonymous) { throw StateError('Authentication is required to restore MotorCloud data.'); } final metadataResult = await _metadata.reconcileMetadata(); return CloudRestoreResult( metadata: metadataResult, // This remains zero until the authenticated R2 download Worker contract // is implemented. Metadata restore is still fully useful on its own. telemetryPending: 0, ); } }