1// Copyright © SixtyFPS GmbH <info@slint.dev>
2// SPDX-License-Identifier: MIT
3
4use serde::{Deserialize, Serialize};
5use std::sync::{Arc, Mutex};
6
7#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
8pub struct CityData {
9 pub lat: f64,
10 pub lon: f64,
11 pub city_name: String,
12}
13
14#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)]
15pub enum WeatherCondition {
16 #[default]
17 Unknown,
18 Sunny,
19 PartiallyCloudy,
20 MostlyCloudy,
21 Cloudy,
22 SunnyRainy,
23 Rainy,
24 Stormy,
25 Snowy,
26 Foggy,
27}
28
29#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)]
30pub struct TemperatureData {
31 pub min: f64,
32 pub max: f64,
33 pub morning: f64,
34 pub day: f64,
35 pub evening: f64,
36 pub night: f64,
37}
38
39#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)]
40pub struct PrecipitationData {
41 pub probability: f64,
42 pub rain_volume: f64,
43 pub snow_volume: f64,
44}
45
46#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)]
47pub struct DayWeatherData {
48 pub condition: WeatherCondition,
49 pub description: String,
50
51 pub current_temperature: f64,
52 pub detailed_temperature: TemperatureData,
53
54 pub precipitation: PrecipitationData,
55 pub uv_index: f64,
56}
57
58#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)]
59pub struct ForecastWeatherData {
60 pub day_name: String,
61 pub weather_data: DayWeatherData,
62}
63
64#[derive(Serialize, Deserialize, Clone)]
65pub struct WeatherData {
66 pub current_data: DayWeatherData,
67 pub forecast_data: Vec<ForecastWeatherData>,
68}
69
70#[derive(Serialize, Deserialize, Clone)]
71pub struct CityWeatherData {
72 pub city_data: CityData,
73 pub weather_data: WeatherData,
74}
75
76#[derive(Serialize, Deserialize, Clone)]
77pub struct GeoLocationData {
78 pub name: String,
79 pub lat: f64,
80 pub lon: f64,
81 pub country: String,
82 pub state: Option<String>,
83}
84
85#[cfg(not(target_arch = "wasm32"))]
86pub type WeatherControllerPointer = Box<dyn WeatherController + Send>;
87#[cfg(target_arch = "wasm32")]
88pub type WeatherControllerPointer = Box<dyn WeatherController + Send + 'static>;
89
90pub type WeatherControllerSharedPointer = Arc<Mutex<WeatherControllerPointer>>;
91
92pub trait WeatherController {
93 fn load(&mut self) -> Result<(), Box<dyn std::error::Error>>;
94 fn save(&self) -> Result<(), Box<dyn std::error::Error>>;
95
96 fn refresh_cities(&mut self) -> Result<Vec<CityWeatherData>, Box<dyn std::error::Error>>;
97
98 fn add_city(
99 &mut self,
100 city: CityData,
101 ) -> Result<Option<CityWeatherData>, Box<dyn std::error::Error>>;
102
103 fn reorder_cities(
104 &mut self,
105 index: usize,
106 new_index: usize,
107 ) -> Result<(), Box<dyn std::error::Error>>;
108
109 fn remove_city(&mut self, index: usize) -> Result<(), Box<dyn std::error::Error>>;
110
111 fn search_location(
112 &self,
113 query: String,
114 ) -> Result<Vec<GeoLocationData>, Box<dyn std::error::Error>>;
115}
116