87 lines
2.4 KiB
Dart
87 lines
2.4 KiB
Dart
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';
|
|
|
|
class FakeRouteProvider implements RouteProvider {
|
|
final bool shouldFail;
|
|
final bool shouldTimeout;
|
|
|
|
FakeRouteProvider({
|
|
this.shouldFail = false,
|
|
this.shouldTimeout = false,
|
|
});
|
|
|
|
@override
|
|
String get name => 'Fake Provider';
|
|
|
|
@override
|
|
Future<RouteCalculationResult> calculateRoute(
|
|
List<RouteStop> stops, {
|
|
bool avoidHighways = false,
|
|
bool avoidTolls = false,
|
|
bool avoidFerries = false,
|
|
}) async {
|
|
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<RouteStop>.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<ResolvedPlace> resolvePlace(String placeId) async {
|
|
if (shouldFail) throw RouteProviderException('placeNotFound', 'Fake not found');
|
|
return ResolvedPlace(
|
|
providerId: placeId,
|
|
displayName: 'Fake Place',
|
|
latitude: 0.0,
|
|
longitude: 0.0,
|
|
attribution: 'Fake Attribution',
|
|
);
|
|
}
|
|
|
|
@override
|
|
Future<List<PlaceSearchResult>> searchPlaces(
|
|
String query, {
|
|
AppLatLng? nearLocation,
|
|
}) async {
|
|
if (shouldFail) throw RouteProviderException('placeSearchUnavailable', 'Fake search error');
|
|
if (query.length < 2) return [];
|
|
|
|
return [
|
|
PlaceSearchResult(
|
|
providerId: 'fake_1',
|
|
primaryText: 'Fake Result 1 for $query',
|
|
secondaryText: 'Fake City',
|
|
attribution: 'Fake Attribution',
|
|
),
|
|
];
|
|
}
|
|
}
|