package com.google.sps.data;
import java.util.List;
import java.util.LinkedList;
import java.util.Arrays;
import java.io.Serializable;
import java.net.URL;
import java.util.logging.Logger;
import com.google.maps.GeoApiContext;
import com.google.maps.PlacesApi;
import com.google.maps.NearbySearchRequest;
import com.google.maps.model.LatLng;
import com.google.maps.model.LocationType;
import com.google.maps.model.Photo;
import com.google.maps.model.PlaceType;
import com.google.maps.model.RankBy;
import com.google.maps.model.Geometry;
import com.google.maps.model.PlacesSearchResponse;
import com.google.maps.model.PlacesSearchResult;

/** SmallCityService object representing all components of the webapp **/
public class SmallCityService {
  
  private User user;
  private BusinessesService businessesService;
  private List<Listing> businesses;
  private final String KEY = "AIzaSyDDIsG-SJAZ69ZoOecmfbXOB7ZIS4pZkAw";
  private final static Logger LOGGER = Logger.getLogger(SmallCityService.class.getName());
  
  public SmallCityService() { }
  
  /** 
  * Create User instance from zipCode and get businesses list
  * @param zipCode inputted zipcode of user
  **/
  public void createUserWithZip(String zipCode) {
    this.user = new User(zipCode);
    findAllBusinesses();
    eliminateBigBusinesses();
  }
  
  /** 
  * Create User instance from geolocation and get businesses list
  * @param mapLocation found geolocation of user
  **/
  public void createUserWithGeolocation(MapLocation mapLocation) {
    this.user = new User(mapLocation);
    businesses = new LinkedList<Listing>();
    businessesService = new BusinessesService(businesses);
    findAllBusinesses();
    eliminateBigBusinesses();
  }
  
  public void findAllBusinesses() {
    businesses = businessesService.getBusinessesFromPlacesApi(user);
  }

  public void eliminateBigBusinesses() {
    // TODO: Parse big business list and remove big businesses from businessList

  }

  public List<Listing> getBusinesses() {
    return businesses;
  }

  private void addListingToBusinesses(PlacesSearchResult place) {
    String name = place.name;
    String formattedAddress = place.vicinity;
    Geometry geometry = place.geometry;
    MapLocation placeLocation = new MapLocation(geometry.location.lat, geometry.location.lng);
    double rating = place.rating;
    Photo photos[] = place.photos;
    String types[] = place.types;
    businesses.add(new Listing(name, formattedAddress, placeLocation, rating, photos, types));
  }
}
@@ -848,80 +848,8 @@
 es;%0A
-  private final String KEY = %22AIzaSyDDIsG-SJAZ69ZoOecmfbXOB7ZIS4pZkAw%22;%0A
   pr
@@ -935,16 +935,16 @@
 ame());%0A
+
   %0A  pub
@@ -1185,46 +1185,15 @@
     
-findAllBusinesses();%0A    elimin
+cre
 ateB
-igB
 usin
@@ -1189,32 +1189,39 @@
 createBusinesses
+Service
 ();%0A  %7D%0A  %0A  /**
@@ -1457,158 +1457,31 @@
     
-businesses = new LinkedList%3CListing%3E();%0A    businessesService = new BusinessesService(businesses);%0A    findAllBusinesses();%0A    eliminateBigBusinesses
+createBusinessesService
 ();%0A
@@ -1813,465 +1813,191 @@
 oid 
-addListingToBusinesses(PlacesSearchResult place) %7B%0A    String name = place.name;%0A    String formattedAddress = place.vicinity;%0A    Geometry geometry = place.geometry;%0A    MapLocation placeLocation = new MapLocation(geometry.location.lat, geometry.location.lng);%0A    double rating = place.rating;%0A    Photo photos%5B%5D = place.photos;%0A    String types%5B%5D = place.types;%0A    businesses.add(new Listing(name, formattedAddress, placeLocation, rating, photos, types)
+createBusinessesService() %7B%0A    businesses = new LinkedList%3CListing%3E();%0A    businessesService = new BusinessesService(businesses);%0A    findAllBusinesses();%0A    eliminateBigBusinesses(
 );%0A 

Fix conflicted