import 'package:anyway/domain/entities/preferences.dart';
import 'package:anyway/domain/entities/trip.dart';
import 'package:anyway/presentation/providers/landmark_providers.dart';

import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:anyway/presentation/providers/core_providers.dart';

// Provides a function that creates a trip given preferences.
final createTripProvider = Provider<Future<Trip> Function(Preferences)>((ref) {
	return (Preferences prefs) async {
		final repo = ref.read(tripRepositoryProvider);
		final landmarks = await repo.searchLandmarks(prefs);
		ref.read(intermediateLandmarksProvider.notifier).setLandmarks(landmarks);
		return repo.getTrip(preferences: prefs, landmarks: landmarks);
	};
});
