package SuMoC.backend.meteo; import com.fasterxml.jackson.annotation.JsonProperty; import java.time.LocalDateTime; import java.util.List; import java.util.Optional; public record ForecastResponse( double latitude, double longitude, @JsonProperty("generationtime_ms") double generationtimeMs, @JsonProperty("utc_offset_seconds") int utcOffsetSeconds, String timezone, @JsonProperty("timezone_abbreviation") String timezoneAbbreviation, double elevation, @JsonProperty("hourly_units") HourlyUnits hourlyUnits, Hourly hourly ) { /** * Gets the weather code for a specific point in time. * * @param dateTime the target date and time * @return the weather code if found, empty otherwise */ public Optional getWeatherCodeAt(LocalDateTime dateTime) { if (hourly == null || hourly.time == null || hourly.weatherCode == null) { return Optional.empty(); } for (int i = 0; i < hourly.time.size(); i++) { if (hourly.time.get(i).equals(dateTime)) { return Optional.of(hourly.weatherCode.get(i)); } } return Optional.empty(); } public record HourlyUnits( String time, @JsonProperty("weather_code") String weatherCode ) { } public record Hourly( List time, @JsonProperty("weather_code") List weatherCode ) { } }