use crate::filters::{base::FilterBand, iir::{iir_filter, IIRFilterDesign}, impls::IIRFilter};

pub struct ButterWorthFilter {
    n: usize,
    wn: Vec<f64>,
    band: FilterBand,
    analog: bool,
    fs: Option<f64>,
}
impl ButterWorthFilter {
    pub fn new(
        n: usize, 
        wn: Vec<f64>, 
        band: FilterBand, 
        analog: bool, 
        fs: Option<f64>) -> Self
    {
        Self { n, wn, band, analog, fs }
    }
}
/// 巴特沃兹滤波器
///
/// # 参数
///
/// - `n`：order
/// - `wn`: cutoff / (fs / 2)。
/// - `btype`：'lowpass', 'highpass'。
/// - `analog`：默认false
/// - `ftype`：'phase', 'delay', 'mag'
/// - `fs`：
///
/// # 返回值
///
/// 滤波器设计参数 Vec<[f64; 6]。
///
/// # 示例
///
/// ```
/// 无
/// ```
/// 
impl<'a> IIRFilterDesign for ButterWorthFilter{
    fn design(&self) -> IIRFilter
    {
        let mut wn = self.wn.clone();
        match iir_filter(self.n, &mut wn, self.band, self.analog, String::from("butter"), self.fs, None, None) {
            Ok(s) => {
                return IIRFilter{
                    sections: s
                };
            },
            Err(_e) => {
                return IIRFilter{
                    sections: vec![]
                }
            }
        }
    }
}