use anyhow::{anyhow, Result};

pub const PRECIPITATION: &str = "â˜”";
pub const WIND: &str = "ğŸ’¨";
pub const CALENDAR: &str = "ğŸ—“ï¸�";
pub const GLOBE: &str = "ğŸŒ�";

pub fn emoji_for_weather<'a>(code: i8) -> Result<&'a str> {
    Ok(match code {
        0..=1 => "â˜€ï¸�",
        2..=3 => "â›…",
        45..=48 => "â˜�ï¸�",
        51..=67 => "ğŸŒ§ï¸�",
        71..=77 => "ğŸŒ¨ï¸�",
        80..=82 => "ğŸŒ§ï¸�",
        85..=86 => "ğŸŒ¨ï¸�",
        95..=99 => "ğŸŒ©ï¸�",
        _ => return Err(anyhow!("Unknown weather code: {}", code)),
    })
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_emoji_for_weather_sunny() {
        let code = 0;
        let result = emoji_for_weather(code).unwrap();
        assert_eq!(result, "â˜€ï¸�");
    }

    #[test]
    fn test_emoji_for_weather_partly_cloudy() {
        let code = 3;
        let result = emoji_for_weather(code).unwrap();
        assert_eq!(result, "â›…");
    }

    #[test]
    fn test_emoji_for_weather_cloudy() {
        let code = 46;
        let result = emoji_for_weather(code).unwrap();
        assert_eq!(result, "â˜�ï¸�");
    }

    #[test]
    fn test_emoji_for_weather_rainy() {
        let code = 55;
        let result = emoji_for_weather(code).unwrap();
        assert_eq!(result, "ğŸŒ§ï¸�");
    }

    #[test]
    fn test_emoji_for_weather_snowy() {
        let code = 75;
        let result = emoji_for_weather(code).unwrap();
        assert_eq!(result, "ğŸŒ¨ï¸�");
    }

    #[test]
    fn test_emoji_for_weather_thunderstorm() {
        let code = 97;
        let result = emoji_for_weather(code).unwrap();
        assert_eq!(result, "ğŸŒ©ï¸�");
    }

    #[test]
    fn test_emoji_for_weather_unknown_code() {
        let code = 100;
        let result = emoji_for_weather(code);
        assert!(result.is_err());
    }
}
