import 'package:motorcycle_dash/services/map/map_provider_interface.dart'; import 'package:motorcycle_dash/services/routes/route_models.dart'; import 'package:motorcycle_dash/services/routes/route_provider.dart'; import 'dart:async'; class FakeRouteProvider implements RouteProvider { final bool shouldFail; final bool shouldTimeout; final List? customSearchResults; final ResolvedPlace? customResolvedPlace; final Future Function(int count)? onCalculate; int _calcCount = 0; List? lastCapturedStops; FakeRouteProvider({ this.shouldFail = false, this.shouldTimeout = false, this.customSearchResults, this.customResolvedPlace, this.onCalculate, }); @override String get name => 'Fake Provider'; @override Future calculateRoute( List stops, { bool avoidHighways = false, bool avoidTolls = false, bool avoidFerries = false, }) async { lastCapturedStops = stops; if (onCalculate != null) { await onCalculate!(_calcCount++); } if (shouldTimeout) { await Future.delayed(const Duration(seconds: 2)); throw RouteProviderException('providerTimeout', 'Fake timeout'); } if (shouldFail) { throw RouteProviderException('routeNotFound', 'Fake route not found'); } if (stops.length < 2) { throw RouteProviderException('invalidRequest', 'Too few stops'); } if (stops.length > 25) { throw RouteProviderException('invalidRequest', 'Too many stops'); } final ordered = List.from(stops); ordered.sort((a, b) => a.order.compareTo(b.order)); final dist = MotorSignalRoute.calculateTotalDistanceMeters(ordered); final geometry = ordered.map((s) => s.latLng).toList(); return RouteCalculationResult( straightLineDistanceMeters: dist, estimatedDistanceMeters: dist * 1.2, estimatedDurationSeconds: (dist / 20).toInt(), geometry: geometry, isStraightLine: false, providerName: name, warnings: ['This is a fake route.'], ); } @override Future> searchPlaces( String query, { AppLatLng? nearLocation, }) async { if (shouldFail) { throw RouteProviderException('placeSearchUnavailable', 'Fake search error'); } if (customSearchResults != null) return customSearchResults!; if (query.length < 2) return []; return [ PlaceSearchResult( providerId: 'fake_1', primaryText: 'Fake Result 1 for $query', secondaryText: 'Fake City', attribution: 'Fake Attribution', ), ]; } @override Future resolvePlace(String providerPlaceId) async { if (shouldFail) { throw RouteProviderException('placeNotFound', 'Fake not found'); } if (customResolvedPlace != null) return customResolvedPlace!; return ResolvedPlace( providerId: providerPlaceId, displayName: 'Fake Place', latitude: 0.0, longitude: 0.0, attribution: 'Fake Attribution', ); } }