#[cfg(test)]
#[path = "./save_tests.rs"]
pub mod save_tests;

use arrayvec::ArrayVec;

use dice::Dice;

pub fn 
(
    dice: &mut Dice,
    save: Option<i32>,
    rend: i32,
    reroll_save_triggers: ArrayVec<[fn(i32, i32) -> bool; ::MAX_CALLBACKS]>,
) -> bool {
    match save {
        Some(save) => {
            let mut save_roll = dice.roll_d6() as i32;
            let modified_save = save - rend;
            if reroll_save_triggers.into_iter().any(|trigger| trigger(save_roll, modified_save)) {
                save_roll = dice.roll_d6() as i32;
            }
            let save_roll = save_roll;

            if save_roll == 1 {
                false
            } else {
                save_roll >= modified_save
            }
        },
        None => false,
    }
}

save