class GeocodeResponse {
  final List<GeocodeResult> results;
  final String status;

  GeocodeResponse({
    required this.results,
    required this.status,
  });

  factory GeocodeResponse.fromJson(Map<String, dynamic> json) {
    final resultsList = (json['results'] as List<dynamic>? ?? [])
        .map((e) => GeocodeResult.fromJson(e as Map<String, dynamic>))
        .toList();

    return GeocodeResponse(
      results: resultsList,
      status: json['status'] ?? '',
    );
  }
  @override
  String toString() {
    return 'GeocodeResponse(status: $status, results: [${results.map((r) => r.toString()).join(', ')}])';
  }
}

class GeocodeResult {
  final String formattedAddress;
  final Geometry geometry;
  final String placeId;

  GeocodeResult({
    required this.formattedAddress,
    required this.geometry,
    required this.placeId,
  });

  factory GeocodeResult.fromJson(Map<String, dynamic> json) {
    return GeocodeResult(
      formattedAddress: json['formatted_address'] ?? '',
      geometry: Geometry.fromJson(json['geometry']),
      placeId: json['place_id'] ?? '',
    );
  }
  @override
  String toString() {
    return 'GeocodeResult(formattedAddress: $formattedAddress, placeId: $placeId, geometry: ${geometry.toString()})';
  }
}

class Geometry {
  final Location location;

  Geometry({required this.location});

  factory Geometry.fromJson(Map<String, dynamic> json) {
    return Geometry(
      location: Location.fromJson(json['location']),
    );
  }

  @override
  String toString() => 'Geometry(location: ${location.toString()})';
}

class Location {
  final double lat;
  final double lng;

  Location({required this.lat, required this.lng});

  factory Location.fromJson(Map<String, dynamic> json) {
    return Location(
      lat: (json['lat'] as num).toDouble(),
      lng: (json['lng'] as num).toDouble(),
    );
    }

  @override
  String toString() => 'Location(lat: $lat, lng: $lng)';
}