// Path: api-core/src/main/java/org/openweathermap/api/DataWeatherClient.java
// public interface DataWeatherClient extends WeatherClient {
// 
//     CurrentWeather getCurrentWeather(CurrentWeatherOneLocationQuery query);
// 
//     List<CurrentWeather> getCurrentWeather(CurrentWeatherMultipleLocationsQuery query);
// 
//     ForecastInformation<HourlyForecast> getForecastInformation(HourlyForecastQuery query);
// 
//     ForecastInformation<DailyForecast> getForecastInformation(DailyForecastQuery query);
// 
//     Uvi getCurrentUvi(CurrentUviQuery query);
// 
//     List<Uvi> getUviForecast(ForecastUviQuery query);
// 
//     List<Uvi> getUviHistory(HistoryUviQuery query);
// }
// 
// Path: api-core/src/main/java/org/openweathermap/api/UrlConnectionDataWeatherClient.java
// public class UrlConnectionDataWeatherClient extends AbstractDataWeatherClient {
//     private static final String ACCEPT_CHARSET = "Accept-Charset";
//     private static final String UTF_8 = "UTF-8";
//     private final String apiKey;
// 
//     public UrlConnectionDataWeatherClient(String apiKey) {
//         this.apiKey = apiKey;
//     }
// 
//     @Override
//     protected String makeRequest(Query query) {
//         String queryString = query.toStringRepresentation(apiKey);
//         try {
//             URL url = getUrl(queryString);
//             URLConnection urlConnection = url.openConnection();
//             urlConnection.setRequestProperty(ACCEPT_CHARSET, UTF_8);
//             return readResponse(urlConnection);
//         } catch (IOException e) {
//             throw new WeatherClientRequestException(e);
//         }
//     }
// 
//     private static String readResponse(URLConnection urlConnection) throws IOException {
//         StringBuilder response = new StringBuilder();
//         try (BufferedReader br = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()))) {
//             String line;
//             while ((line = br.readLine()) != null) {
//                 response.append(line);
//             }
//         }
//         return response.toString();
//     }
// 
//     /**
//      * Gets url from query string.
//      *
//      * @param query the query
//      * @return the url
//      */
//     private static URL getUrl(String query) {
//         try {
//             return new URL(query);
//         } catch (MalformedURLException e) {
//             throw new RuntimeException("Malformed query", e);
//         }
//     }
// 
// }
// 
// Path: api-model/src/main/java/org/openweathermap/api/model/currentweather/CurrentWeather.java
// @EqualsAndHashCode(callSuper = true)
// @Data
// public class CurrentWeather extends AbstractWeatherInformation {
// 
//     public static final Type TYPE = TypeToken.get(CurrentWeather.class).getType();
//     public static final Type TYPE_LIST = TypeToken.getParameterized(List.class, TYPE).getType();
// 
//     @SerializedName("coord")
//     private Coordinate coordinate;
// 
//     private String base;
// 
//     @SerializedName("name")
//     private String cityName;
// 
//     @SerializedName("id")
//     private long cityId;
// 
//     private String cod;
// 
//     private String visibility;
// 
//     @SerializedName("sys")
//     private SystemParameters systemParameters;
// }
// 
// Path: api-query/src/main/java/org/openweathermap/api/query/currentweather/CurrentWeatherOneLocationQuery.java
// public interface CurrentWeatherOneLocationQuery extends QueryWithResponseFormat {
//     String SEARCH_PATH = "/weather";
// }


import org.openweathermap.api.DataWeatherClient;
import org.openweathermap.api.UrlConnectionDataWeatherClient;
import org.openweathermap.api.model.currentweather.CurrentWeather;
import org.openweathermap.api.query.*;
import org.openweathermap.api.query.currentweather.CurrentWeatherOneLocationQuery;
/*
 * Copyright 2021, Yurii Serhiichuk
 *
 * 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 org.openweathermap.api.example;



public class CurrentWeatherOneLocationExample {
    private static final String API_KEY = System.getenv("OPENWEATHERMAP_API_KEY");

    public static void main(String[] args) {
        DataWeatherClient client = new UrlConnectionDataWeatherClient(API_KEY);
        CurrentWeatherOneLocationQuery currentWeatherOneLocationQuery = QueryBuilderPicker.pick()
                .currentWeather()                   // get current weather
                .oneLocation()                      // for one location
                .byCityName("Kharkiv")              // for Kharkiv city
                .countryCode("UA")                  // in Ukraine
                .type(Type.ACCURATE)                // with Accurate search
                .language(Language.ENGLISH)         // in English language
                .responseFormat(ResponseFormat.JSON)// with JSON response format
                .unitFormat(UnitFormat.METRIC)      // in metric units
                .build();
        CurrentWeather currentWeather = client.getCurrentWeather(currentWeatherOneLocationQuery);
        System.out.println(prettyPrint(currentWeather));
    }

// Path: api-core/src/main/java/org/openweathermap/api/DataWeatherClient.java
// public interface DataWeatherClient extends WeatherClient {
// 
//     CurrentWeather getCurrentWeather(CurrentWeatherOneLocationQuery query);
// 
//     List<CurrentWeather> getCurrentWeather(CurrentWeatherMultipleLocationsQuery query);
// 
//     ForecastInformation<HourlyForecast> getForecastInformation(HourlyForecastQuery query);
// 
//     ForecastInformation<DailyForecast> getForecastInformation(DailyForecastQuery query);
// 
//     Uvi getCurrentUvi(CurrentUviQuery query);
// 
//     List<Uvi> getUviForecast(ForecastUviQuery query);
// 
//     List<Uvi> getUviHistory(HistoryUviQuery query);
// }
// 
// Path: api-core/src/main/java/org/openweathermap/api/UrlConnectionDataWeatherClient.java
// public class UrlConnectionDataWeatherClient extends AbstractDataWeatherClient {
//     private static final String ACCEPT_CHARSET = "Accept-Charset";
//     private static final String UTF_8 = "UTF-8";
//     private final String apiKey;
// 
//     public UrlConnectionDataWeatherClient(String apiKey) {
//         this.apiKey = apiKey;
//     }
// 
//     @Override
//     protected String makeRequest(Query query) {
//         String queryString = query.toStringRepresentation(apiKey);
//         try {
//             URL url = getUrl(queryString);
//             URLConnection urlConnection = url.openConnection();
//             urlConnection.setRequestProperty(ACCEPT_CHARSET, UTF_8);
//             return readResponse(urlConnection);
//         } catch (IOException e) {
//             throw new WeatherClientRequestException(e);
//         }
//     }
// 
//     private static String readResponse(URLConnection urlConnection) throws IOException {
//         StringBuilder response = new StringBuilder();
//         try (BufferedReader br = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()))) {
//             String line;
//             while ((line = br.readLine()) != null) {
//                 response.append(line);
//             }
//         }
//         return response.toString();
//     }
// 
//     /**
//      * Gets url from query string.
//      *
//      * @param query the query
//      * @return the url
//      */
//     private static URL getUrl(String query) {
//         try {
//             return new URL(query);
//         } catch (MalformedURLException e) {
//             throw new RuntimeException("Malformed query", e);
//         }
//     }
// 
// }
// 
// Path: api-model/src/main/java/org/openweathermap/api/model/currentweather/CurrentWeather.java
// @EqualsAndHashCode(callSuper = true)
// @Data
// public class CurrentWeather extends AbstractWeatherInformation {
// 
//     public static final Type TYPE = TypeToken.get(CurrentWeather.class).getType();
//     public static final Type TYPE_LIST = TypeToken.getParameterized(List.class, TYPE).getType();
// 
//     @SerializedName("coord")
//     private Coordinate coordinate;
// 
//     private String base;
// 
//     @SerializedName("name")
//     private String cityName;
// 
//     @SerializedName("id")
//     private long cityId;
// 
//     private String cod;
// 
//     private String visibility;
// 
//     @SerializedName("sys")
//     private SystemParameters systemParameters;
// }
// 
// Path: api-query/src/main/java/org/openweathermap/api/query/currentweather/CurrentWeatherOneLocationQuery.java
// public interface CurrentWeatherOneLocationQuery extends QueryWithResponseFormat {
//     String SEARCH_PATH = "/weather";
// }


// Path: api-examples/src/main/java/org/openweathermap/api/example/CurrentWeatherOneLocationExample.java
import org.openweathermap.api.DataWeatherClient;
import org.openweathermap.api.UrlConnectionDataWeatherClient;
import org.openweathermap.api.model.currentweather.CurrentWeather;
import org.openweathermap.api.query.*;
import org.openweathermap.api.query.currentweather.CurrentWeatherOneLocationQuery;

/*
 * Copyright 2021, Yurii Serhiichuk
 *
 * 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 org.openweathermap.api.example;



public class CurrentWeatherOneLocationExample {
    private static final String API_KEY = System.getenv("OPENWEATHERMAP_API_KEY");

    public static void main(String[] args) {
        DataWeatherClient client = new UrlConnectionDataWeatherClient(API_KEY);
        CurrentWeatherOneLocationQuery currentWeatherOneLocationQuery = QueryBuilderPicker.pick()
                .currentWeather()                   // get current weather
                .oneLocation()                      // for one location
                .byCityName("Kharkiv")              // for Kharkiv city
                .countryCode("UA")                  // in Ukraine
                .type(Type.ACCURATE)                // with Accurate search
                .language(Language.ENGLISH)         // in English language
                .responseFormat(ResponseFormat.JSON)// with JSON response format
                .unitFormat(UnitFormat.METRIC)      // in metric units
                .build();
        CurrentWeather currentWeather = client.getCurrentWeather(currentWeatherOneLocationQuery);
        System.out.println(prettyPrint(currentWeather));
    }

    private static String prettyPrint(CurrentWeather currentWeather) {