/*
 * Copyright 2018 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.sps.data;

// Imports the Google Cloud client library
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.maps.GeoApiContext;
import com.google.maps.GeocodingApi;
import com.google.maps.TimeZoneApi;
import com.google.maps.model.GeocodingResult;
import com.google.maps.model.LatLng;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.TimeZone;

/*  Location object, always contains the following properties:
 **    address: inputted address parameter passed to constructor
 **
 **  If Geocoding API call was successful, the following properties are valid
 **  Otherwise, they remain uninitialized:
 **    formattedAddress: Geocoding API formatted address
 **    coords: Latitude, Longitude coordinates returned from Geocoding API
 **    latCoord: Latitude coordinate returned from Geocoding API
 **    lngCoord: Longitude, Longitude coordinates returned from Geocoding API
 **    lngCoord: Longitude, Longitude coordinates returned from Geocoding API
 **
 **  If Timezone API call was successful, the following properties are valid
 **  Otherwise, they remain uninitialized:
 **    timeZoneObj: TimeZone Object for corresponding location
 **    timeZoneID: Time zone ID for the corresponding location (ex. "America/Los_Angeles")
 **    timeZoneName: Time zone name for corresponding location (ex. "Pacific Standard Time")
 **    lngCoord: Longitude, Longitude coordinates returned from Geocoding API
 */
public class Location {
  private String address;
  private String formattedAddress;
  private double latCoord;
  private double lngCoord;
  private LatLng coords;
  private TimeZone timeZoneObj;
  private String timeZoneID;
  private String timeZoneName;

  public Location(String address) {
    this.address = address;
    setProperties();
  }

  public void setProperties() {
    try {
      String apiKey =
          new String(
              Files.readAllBytes(Paths.get(getClass().getResource("/files/apikey.txt").getFile())));
      GeoApiContext context = new GeoApiContext.Builder().apiKey(apiKey).build();
      setCoordinates(context, address);
      setTimeZone(context, coords);
    } catch (IOException e) {
      System.out.println("API key for maps not found.");
    }
  }

  public void setCoordinates(GeoApiContext context, String address) {
    try {
      GeocodingResult[] results = GeocodingApi.geocode(context, address).await();
      Gson gson = new GsonBuilder().setPrettyPrinting().create();
      this.coords = new LatLng(results[0].geometry.location.lat, results[0].geometry.location.lng);
      this.latCoord = coords.lat;
      this.lngCoord = coords.lng;
      this.formattedAddress = results[0].formattedAddress;
    } catch (Exception e) {
      return;
    }
  }

  public void setTimeZone(GeoApiContext context, LatLng location) {
    try {
      TimeZone results = TimeZoneApi.getTimeZone(context, location).await();
      Gson gson = new GsonBuilder().setPrettyPrinting().create();
      this.timeZoneObj = results;
      this.timeZoneID = results.getID();
      this.timeZoneName = results.getDisplayName();
    } catch (Exception e) {
      return;
    }
  }

  public String getAddress() {
    return this.address;
  }

  public String getAddressFormatted() {
    return this.formattedAddress;
  }

  public Double getLat() {
    return this.latCoord;
  }

  public Double getLng() {
    return this.lngCoord;
  }

  public LatLng getCoords() {
    return this.coords;
  }

  public String getTimeZoneID() {
    return this.timeZoneID;
  }

  public String getTimeZoneName() {
    return this.timeZoneName;
  }

  public TimeZone getTimeZone() {
    return this.timeZoneObj;
  }
}

@@ -1031,16 +1031,17 @@
 one;%0A%0A/*
+*
   Locati
@@ -1091,25 +1091,24 @@
 operties:%0A *
-*
     address:
@@ -1159,21 +1159,19 @@
 uctor%0A *
-*
 %0A *
-*
   If Geo
@@ -1231,33 +1231,32 @@
 ies are valid%0A *
-*
   Otherwise, the
@@ -1277,25 +1277,24 @@
 tialized:%0A *
-*
     formatte
@@ -1337,17 +1337,16 @@
 dress%0A *
-*
     coor
@@ -1407,25 +1407,24 @@
 oding API%0A *
-*
     latCoord
@@ -1467,33 +1467,32 @@
 Geocoding API%0A *
-*
     lngCoord: Lo
@@ -1552,17 +1552,16 @@
 g API%0A *
-*
     lngC
@@ -1633,13 +1633,11 @@
 I%0A *
-*
 %0A *
-*
   If
@@ -1708,17 +1708,16 @@
 valid%0A *
-*
   Otherw
@@ -1750,17 +1750,16 @@
 ized:%0A *
-*
     time
@@ -1812,17 +1812,16 @@
 ation%0A *
-*
     time
@@ -1898,25 +1898,24 @@
 Angeles%22)%0A *
-*
     timeZone
@@ -1994,17 +1994,16 @@
 ime%22)%0A *
-*
     lngC
@@ -2073,16 +2073,17 @@
 API%0A */%0A
+%0A
 public c

Fix comment block formatting