// Path: aula33-weather-async/src/main/java/weather/WeatherService.java
// public class WeatherService implements AutoCloseable{
// 
//     private final WeatherWebApi api;
// 
//     public WeatherService(WeatherWebApi api) {
//         this.api = api;
//     }
// 
//     public WeatherService() {
//         api = new WeatherWebApi(new HttpRequest());
//     }
// 
//     public CompletableFuture<Stream<Location>> search(String query) {
//         return api.search(query)
//                 .thenApply(str -> str
//                     .map(this::dtoToLocation));
//     }
// 
//     protected Location dtoToLocation(LocationDto loc) {
//         return new Location(
//                 loc.getCountry(),
//                 loc.getRegion(),
//                 loc.getLatitude(),
//                 loc.getLongitude(),
//                 last30daysWeather(loc.getLatitude(), loc.getLongitude())::join,
//                 (from, to) -> pastWeather(loc.getLatitude(), loc.getLongitude(), from, to).join());
//     }
// 
//     public CompletableFuture<Stream<WeatherInfo>> last30daysWeather(double lat, double log) {
//         return this.pastWeather(lat, log, now().minusDays(30), now().minusDays(1));
//     }
// 
//     private static WeatherInfo dtoToWeatherInfo(WeatherInfoDto dto) {
//         return new WeatherInfo(
//                 dto.getDate(),
//                 dto.getTempC(),
//                 dto.getDescription(),
//                 dto.getPrecipMM(),
//                 dto.getFeelsLikeC());
//     }
// 
//     public CompletableFuture<Stream<WeatherInfo>> pastWeather(double lat, double log, LocalDate from, LocalDate to) {
//         return api
//                 .pastWeather(lat, log, from, to)
//                 .thenApply(str -> str
//                     .map(dto -> dtoToWeatherInfo(dto)));
//     }
// 
//     @Override
//     public void close() throws Exception {
//         api.close();
//     }
// }
// 
// Path: aula19-optional-and-default-methods/src/main/java/weather/model/Location.java
// public class Location {
//     private final String country;
//     private final String region;
//     private final double latitude;
//     private final double longitude;
//     private final Iterable<WeatherInfo> last30daysWeather;
//     private final BiFunction<LocalDate, LocalDate, Iterable<WeatherInfo>> pastWeather;
// 
//     public Location(String country, String region, double latitude, double longitude, Iterable<WeatherInfo> last30daysWeather, BiFunction<LocalDate, LocalDate, Iterable<WeatherInfo>> pastWeather) {
//         this.country = country;
//         this.region = region;
//         this.latitude = latitude;
//         this.longitude = longitude;
//         this.last30daysWeather = last30daysWeather;
//         this.pastWeather = pastWeather;
//     }
// 
//     public String getCountry() {
//         return country;
//     }
// 
//     public String getRegion() {
//         return region;
//     }
// 
//     public double getLatitude() {
//         return latitude;
//     }
// 
//     public double getLongitude() {
//         return longitude;
//     }
// 
//     public Iterable<WeatherInfo> getLast30daysWeather() {
//         return last30daysWeather;
//     }
// 
//     public Iterable<WeatherInfo> getPastWeather(LocalDate from, LocalDate to) {
//         return pastWeather.apply(from, to);
//     }
// 
//     @Override
//     public String toString() {
//         return "Location{" +
//                 "country='" + country + '\'' +
//                 ", region='" + region + '\'' +
//                 ", latitude=" + latitude +
//                 ", longitude=" + longitude +
//                 ", last30daysWeather=" + last30daysWeather +
//                 '}';
//     }
// }


import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import static java.lang.ClassLoader.getSystemResource;
import static java.nio.file.Files.lines;
import weather.WeatherService;
import weather.model.Location;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.CompletableFuture;
        }
        return last30days;
    }

    private String loadLast30daysWeather(double lat, double log) {
        String path = root + lat + "-" + log + ".html";
        File file = new File(path);
        URI uri = !file.exists() ? null : file.toURI();
        return uri == null ? null : load(uri);
    }

    private String writeLast30daysWeather(double lat, double log, String view) {
        try {
            String path = root + lat + "-" + log + ".html";
            try (FileWriter fw = new FileWriter(path)) {
                fw.write(view);
                fw.flush();
            }
        }catch (IOException e) {
            throw new RuntimeException(e);
        }
        return view;
    }

    private static String linkForLocation(Location l) {
        return String.format("<a href=\"/weather/%s/%s/last30days/\">%s</a>",
                l.getLatitude(), l.getLongitude(), l.getRegion());
    }

    private static String load(String path) {
// Path: aula33-weather-async/src/main/java/weather/WeatherService.java
// public class WeatherService implements AutoCloseable{
// 
//     private final WeatherWebApi api;
// 
//     public WeatherService(WeatherWebApi api) {
//         this.api = api;
//     }
// 
//     public WeatherService() {
//         api = new WeatherWebApi(new HttpRequest());
//     }
// 
//     public CompletableFuture<Stream<Location>> search(String query) {
//         return api.search(query)
//                 .thenApply(str -> str
//                     .map(this::dtoToLocation));
//     }
// 
//     protected Location dtoToLocation(LocationDto loc) {
//         return new Location(
//                 loc.getCountry(),
//                 loc.getRegion(),
//                 loc.getLatitude(),
//                 loc.getLongitude(),
//                 last30daysWeather(loc.getLatitude(), loc.getLongitude())::join,
//                 (from, to) -> pastWeather(loc.getLatitude(), loc.getLongitude(), from, to).join());
//     }
// 
//     public CompletableFuture<Stream<WeatherInfo>> last30daysWeather(double lat, double log) {
//         return this.pastWeather(lat, log, now().minusDays(30), now().minusDays(1));
//     }
// 
//     private static WeatherInfo dtoToWeatherInfo(WeatherInfoDto dto) {
//         return new WeatherInfo(
//                 dto.getDate(),
//                 dto.getTempC(),
//                 dto.getDescription(),
//                 dto.getPrecipMM(),
//                 dto.getFeelsLikeC());
//     }
// 
//     public CompletableFuture<Stream<WeatherInfo>> pastWeather(double lat, double log, LocalDate from, LocalDate to) {
//         return api
//                 .pastWeather(lat, log, from, to)
//                 .thenApply(str -> str
//                     .map(dto -> dtoToWeatherInfo(dto)));
//     }
// 
//     @Override
//     public void close() throws Exception {
//         api.close();
//     }
// }
// 
// Path: aula19-optional-and-default-methods/src/main/java/weather/model/Location.java
// public class Location {
//     private final String country;
//     private final String region;
//     private final double latitude;
//     private final double longitude;
//     private final Iterable<WeatherInfo> last30daysWeather;
//     private final BiFunction<LocalDate, LocalDate, Iterable<WeatherInfo>> pastWeather;
// 
//     public Location(String country, String region, double latitude, double longitude, Iterable<WeatherInfo> last30daysWeather, BiFunction<LocalDate, LocalDate, Iterable<WeatherInfo>> pastWeather) {
//         this.country = country;
//         this.region = region;
//         this.latitude = latitude;
//         this.longitude = longitude;
//         this.last30daysWeather = last30daysWeather;
//         this.pastWeather = pastWeather;
//     }
// 
//     public String getCountry() {
//         return country;
//     }
// 
//     public String getRegion() {
//         return region;
//     }
// 
//     public double getLatitude() {
//         return latitude;
//     }
// 
//     public double getLongitude() {
//         return longitude;
//     }
// 
//     public Iterable<WeatherInfo> getLast30daysWeather() {
//         return last30daysWeather;
//     }
// 
//     public Iterable<WeatherInfo> getPastWeather(LocalDate from, LocalDate to) {
//         return pastWeather.apply(from, to);
//     }
// 
//     @Override
//     public String toString() {
//         return "Location{" +
//                 "country='" + country + '\'' +
//                 ", region='" + region + '\'' +
//                 ", latitude=" + latitude +
//                 ", longitude=" + longitude +
//                 ", last30daysWeather=" + last30daysWeather +
//                 '}';
//     }
// }


// Path: aula34-weather-webapp/src/main/java/weather/controllers/WeatherController.java
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import static java.lang.ClassLoader.getSystemResource;
import static java.nio.file.Files.lines;
import weather.WeatherService;
import weather.model.Location;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.CompletableFuture;

        }
        return last30days;
    }

    private String loadLast30daysWeather(double lat, double log) {
        String path = root + lat + "-" + log + ".html";
        File file = new File(path);
        URI uri = !file.exists() ? null : file.toURI();
        return uri == null ? null : load(uri);
    }

    private String writeLast30daysWeather(double lat, double log, String view) {
        try {
            String path = root + lat + "-" + log + ".html";
            try (FileWriter fw = new FileWriter(path)) {
                fw.write(view);
                fw.flush();
            }
        }catch (IOException e) {
            throw new RuntimeException(e);
        }
        return view;
    }

    private static String linkForLocation(Location l) {
        return String.format("<a href=\"/weather/%s/%s/last30days/\">%s</a>",
                l.getLatitude(), l.getLongitude(), l.getRegion());
    }

    private static String load(String path) {
        return load(ClassLoader.getSystemResource(path));