use std::collections::HashSet;

#[derive(Default)]
pub struct MuteState {
    pub muted: HashSet<(usize, usize)>,
    pub soloed: HashSet<(usize, usize)>,
}

impl MuteState {
    pub fn toggle_mute(&mut self, bank: usize, pattern: usize) {
        let key = (bank, pattern);
        if self.muted.contains(&key) {
            self.muted.remove(&key);
        } else {
            self.muted.insert(key);
        }
    }

    pub fn toggle_solo(&mut self, bank: usize, pattern: usize) {
        let key = (bank, pattern);
        if self.soloed.contains(&key) {
            self.soloed.remove(&key);
        } else {
            self.soloed.insert(key);
        }
    }

    pub fn clear_mute(&mut self) {
        self.muted.clear();
    }

    pub fn clear_solo(&mut self) {
        self.soloed.clear();
    }

    pub fn is_muted(&self, bank: usize, pattern: usize) -> bool {
        self.muted.contains(&(bank, pattern))
    }

    pub fn is_soloed(&self, bank: usize, pattern: usize) -> bool {
        self.soloed.contains(&(bank, pattern))
    }

    pub fn is_effectively_muted(&self, bank: usize, pattern: usize) -> bool {
        if self.muted.contains(&(bank, pattern)) {
            return true;
        }
        if !self.soloed.is_empty() && !self.soloed.contains(&(bank, pattern)) {
            return true;
        }
        false
    }
}
