use std::hash::Hash;

#[derive(Clone, Debug)]
pub struct FlowCondition<Qs: Eq + Hash + Clone> {
    pub answer: String, // Previous answer maybe?
    pub next: Qs,
}

/// An object that allows us to move from one question to another based on the answer of a previous question.
///
/// `Qs` is the type fo question and is used as a unique identifier for a question.
#[derive(Clone, Debug)]
pub struct QuestionFlow<Qs: Eq + Hash + Clone> {
    pub conditions: Vec<FlowCondition<Qs>>,
    pub default: Option<Qs>,
}

impl<Qs: Eq + Hash + Clone> Default for QuestionFlow<Qs> {
    fn default() -> Self {
        Self::new()
    }
}

impl<Qs: Eq + Hash + Clone> QuestionFlow<Qs> {
    pub fn new() -> Self {
        Self {
            conditions: Vec::new(),
            default: None,
        }
    }

    pub fn add_condition(mut self, answer: &str, next: Qs) -> Self {
        self.conditions.push(FlowCondition {
            answer: answer.to_string(),
            next,
        });
        self
    }

    pub fn set_default(mut self, next: Qs) -> Self {
        self.default = Some(next);
        self
    }
}
