use chrono::{DateTime};
use chrono_tz::Tz;

#[derive(Clone, PartialEq)]
pub struct Sport {
    pub name: String,
    pub variations: Option<Vec<String>>,  // meant to be appended to end of sport name
    pub divisions: Vec<String>,
    pub date_format: String,
    pub season_start: String,
    pub season_end: String,
    pub weeks: Option<u8>,
}

impl Sport {
    /// Compute the date string that should be used to query API
    /// E.g. football requires weeks (2022/01, 2022/02, etc.) while basketball
    /// requires normal date (2022/11/28)
    /// Playoffs for some sports also require unique date strings
    /// Return None if out of season
    pub fn get_date_str(&self, date: DateTime<Tz>) -> Option<String> {
        let result_str = date.format(&self.date_format).to_string();

        if self.weeks != None {
            println!("weeks is not None for sport {}!", self.name);
        }

        Some(result_str)
    }
}

pub fn supported_sports() -> Vec<Sport> {
    let default_variations = Some(vec!["-men".to_string(), "-women".to_string()]);
    let default_divisions = vec!["d1".to_string(), "d2".to_string()];
    let default_date_format = "%Y/%m/%d".to_string();

    let sports = vec![
        Sport{
            name: "basketball".to_string(),
            variations: default_variations.clone(),
            divisions: default_divisions.clone(),
            date_format: default_date_format.clone(),
            season_start: "2022/11/07".to_string(),
            season_end: "2023/03/31".to_string(),
            weeks: None,
        },
        Sport{
            name: "football".to_string(),
            variations: None,
            divisions: vec!["fbs".to_string()],
            date_format: "%Y/WW".to_string(),
            season_start: "2022/08/27".to_string(),  // "week 0"
            season_end: "2022/12/10".to_string(),
            weeks: Some(15),
        },
        Sport{
            name: "soccer".to_string(),
            variations: default_variations.clone(),
            divisions: default_divisions.clone(),
            date_format: default_date_format.clone(),
            season_start: "2022/08/18".to_string(),
            season_end: "2022/11/30".to_string(),
            weeks: None,
        }
    ];
    sports
}