pub struct Allergies(pub u32);

#[derive(Debug, PartialEq)]
pub enum Allergen {
    Eggs,
    Peanuts,
    Shellfish,
    Strawberries,
    Tomatoes,
    Chocolate,
    Pollen,
    Cats,
}

impl Allergies {
    pub fn new(score: u32) -> Self {
        Allergies(score)
    }

    pub fn is_allergic_to(&self, allergen: &Allergen) -> bool {
        let index = Self::allergens().iter().position(|x: &Allergen| x == allergen).unwrap();
        (self.0 & (1 << index as u32)) != 0
    }

    pub fn allergies(&self) -> Vec<Allergen> {
        Self::allergens().iter().map(|x: &Allergen| self.is_allergic_to(x)).collect::<Vec<Allergen>>()
    }

    fn allergens() -> Vec<Allergen> {
        vec![
            Allergen::Eggs,
            Allergen::Peanuts,
            Allergen::Shellfish,
            Allergen::Strawberries,
            Allergen::Tomatoes,
            Allergen::Chocolate,
            Allergen::Pollen,
            Allergen::Cats,
        ]
    }
}
