import 'dart:async';

class MapLocationRequest {
  final double latitude;
  final double longitude;
  final String? name;
  final DateTime timestamp;

  MapLocationRequest({
    required this.latitude,
    required this.longitude,
    this.name,
  }) : timestamp = DateTime.now();
}

class MapNavigationService {
  final _requestController = StreamController<MapLocationRequest>.broadcast();
  MapLocationRequest? _lastRequest;

  Stream<MapLocationRequest> get requestStream => _requestController.stream;
  MapLocationRequest? get lastRequest => _lastRequest;

  void navigateToLocation(double lat, double lng, {String? name}) {
    final request = MapLocationRequest(
      latitude: lat,
      longitude: lng,
      name: name,
    );
    _lastRequest = request;
    _requestController.add(request);
  }

  void dispose() {
    _requestController.close();
  }
}
