diff --git a/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/model/Location.kt b/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/model/Location.kt new file mode 100644 index 0000000..a3f822c --- /dev/null +++ b/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/model/Location.kt @@ -0,0 +1,34 @@ +package org.jetbrains.plugins.template.weatherApp.model + +import androidx.compose.runtime.Immutable + +/** + * Represents a location with a name and associated country. + * + * @property name The name of the location. + * @property country The associated country of the location. + * @property id A derived unique identifier for the location in the format `name, country`. + */ +@Immutable +internal data class Location(val name: String, val country: String) : PreviewableItem, Searchable { + val id: String = "$name, $country" + + override fun isSearchApplicable(query: String): Boolean { + val applicableCandidates = listOf( + id, + name, + country, + name.split(" ").map { it.first() }.joinToString(""), + "${name.first()}${country.first()}", + "${country.first()}${name.first()}" + ) + + return applicableCandidates.any { it.contains(query, ignoreCase = true) } + } + + override val label: String + get() = id +} + +@Immutable +internal data class SelectableLocation(val location: Location, val isSelected: Boolean) \ No newline at end of file diff --git a/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/model/PreviewableItem.kt b/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/model/PreviewableItem.kt new file mode 100644 index 0000000..4d97d35 --- /dev/null +++ b/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/model/PreviewableItem.kt @@ -0,0 +1,5 @@ +package org.jetbrains.plugins.template.weatherApp.model + +interface PreviewableItem { + val label: String +} \ No newline at end of file diff --git a/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/model/Searchable.kt b/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/model/Searchable.kt new file mode 100644 index 0000000..5bafa75 --- /dev/null +++ b/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/model/Searchable.kt @@ -0,0 +1,8 @@ +package org.jetbrains.plugins.template.weatherApp.model + +/** + * Represents an entity that can be filtered by a search query. + */ +internal interface Searchable { + fun isSearchApplicable(query: String): Boolean +} \ No newline at end of file diff --git a/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/model/WeatherForecastData.kt b/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/model/WeatherForecastData.kt new file mode 100644 index 0000000..84a423f --- /dev/null +++ b/src/main/kotlin/org/jetbrains/plugins/template/weatherApp/model/WeatherForecastData.kt @@ -0,0 +1,62 @@ +package org.jetbrains.plugins.template.weatherApp.model + +import java.time.LocalDateTime + +/** + * Data class representing weather information to be displayed in the Weather Card. + */ +data class WeatherForecastData( + val cityName: String, + val temperature: Float, + val currentTime: LocalDateTime, + val windSpeed: Float, + val windDirection: WindDirection, + val humidity: Int, // Percentage + val weatherType: WeatherType +) { + companion object Companion { + val EMPTY: WeatherForecastData = WeatherForecastData( + "", + 0f, + LocalDateTime.now(), + 0f, + WindDirection.NORTH, + 0, + WeatherType.SUNNY + ) + } +} + +/** + * Enum representing different weather types. + */ +enum class WeatherType(val label: String) { + SUNNY("Sunny"), + CLOUDY("Cloudy"), + PARTLY_CLOUDY("Partly Cloudy"), + RAINY("Rainy"), + SNOWY("Snowy"), + STORMY("Stormy"); + + companion object { + fun random(): WeatherType = entries.toTypedArray().random() + } +} + +/** + * Enum representing wind directions. + */ +enum class WindDirection(val label: String) { + NORTH("N"), + NORTH_EAST("NE"), + EAST("E"), + SOUTH_EAST("SE"), + SOUTH("S"), + SOUTH_WEST("SW"), + WEST("W"), + NORTH_WEST("NW"); + + companion object { + fun random(): WindDirection = entries.toTypedArray().random() + } +} \ No newline at end of file