extern crate regex;

use regex::Regex;

struct ParsedTimeStr {
    finded_time: String,
    finded_type: String,
}

pub struct TimeStr {
    time_string: String,
}

impl TimeStr {
    pub fn new(t_str: &str) -> TimeStr {
        TimeStr {
            time_string: t_str.to_string(),        
        }    
    }
    
    fn parse_str_time(&self) -> ParsedTimeStr {
        let re = Regex::new(r"(\d+)(h|m|s)").unwrap();
        let caps = re.captures(&self.time_string[..]).unwrap();
        
        let mut f_time = "";
        let mut f_type = "";        
        
        match caps.at(1) {
            Some(time) => f_time = time,
            None => panic!("Bad format"),
        }

        match caps.at(2) {
            Some(t_type) => f_type = t_type,
            None => panic!("Bad format"),
        }
        
        ParsedTimeStr {
            finded_time: f_time.to_string(),
            finded_type: f_type.to_string(),
        }

    }

    pub fn to_seconds(&self) -> u32 {
            
        let parsed_string = self.parse_str_time();
        let i_time: u32 = parsed_string.finded_time.parse::<u32>().unwrap();

        if parsed_string.finded_type == "h" 

        
        if parsed_string.finded_type == "m" {
            return i_time * 60;
        }

        return i_time;
        
    }
}


#[test]
fn test_hours() {

    let p1 = TimeStr::new("1h");
    assert_eq!(3600, p1.to_seconds());

    let p2 = TimeStr::new("10h");
    assert_eq!(36000, p2.to_seconds());
    
    let p3 = TimeStr::new("5h");
    assert_eq!(18000, p3.to_seconds());    
}

#[test]
fn test_minutes() {
    let p1 = TimeStr::new("1m");
    assert_eq!(60, p1.to_seconds());

    let p2 = TimeStr::new("10m");
    assert_eq!(600, p2.to_seconds());
    
    let p3 = TimeStr::new("5m");
    assert_eq!(300, p3.to_seconds());
}

#[test]
fn test_seconds() {
    let p1 = TimeStr::new("1s");
    assert_eq!(1, p1.to_seconds());

    let p2 = TimeStr::new("10s");
    assert_eq!(10, p2.to_seconds());
    
    let p3 = TimeStr::new("5s");
    assert_eq!(5, p3.to_seconds());
}

#[test]
#[should_panic]
fn test_bad_format() {
    let p1 = TimeStr::new("100a");
    p1.to_seconds();
}



{
            return i_time * 60 * 60;
        }