1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
pub mod air_pollution;
pub mod forecast;
pub mod current;
pub mod one_call;
pub mod geocoding;
pub mod maps;

pub use air_pollution::AirPollution;
pub use forecast::Forecast;
pub use one_call::{OneCall, Fields};
pub use geocoding::Geocoding;
pub use maps::Maps;

use std::fmt;
use serde::{ Serialize, Deserialize};
use crate::units::Units;
use crate::languages::Language;

use self::current::Current;

#[derive(Debug, Serialize, Deserialize, PartialOrd, PartialEq, Default, Clone)]
pub struct OpenWeather {
    pub one_call: OneCall,
    pub forecast: Forecast,
    pub current: Current,
    pub maps: Maps,
    pub air_pollution: AirPollution,
    pub geocoding: Geocoding
}

impl fmt::Display for OpenWeather {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(
            f,
            "OpenWeather: (one_call: {}, forecast: {}, maps: {}, air_pollution: {}, geocoding: {})",
            self.one_call,
            self.forecast,
            self.maps,
            self.air_pollution,
            self.geocoding
        )
    }
}

impl OpenWeather {
    pub fn new(api_key: String, units: Units, language: Language) -> Self {
        Self {
            one_call: OneCall::new(api_key.clone(), units, language),
            forecast: Forecast::new(api_key.clone(), units, language),
            current: Current::new(api_key.clone(), units, language),
            maps: Maps::new(api_key.clone()),
            air_pollution: AirPollution::new(api_key.clone()),
            geocoding: Geocoding::new(api_key.clone())
        }
    }
}