use super::WriteElement;

/// [feTurbulence](https://www.w3.org/TR/SVG11/filters.html#feTurbulenceElement)
#[derive(Debug)]
pub struct Turbulence {
    pub base_frequency: (f32, f32),
    pub num_octaves: u16,
    pub seed: u32,
    pub stitch_tiles: StitchTiles,
    // attr name: type
    pub noise_type: NoiseType,
}

impl WriteElement for Turbulence {
    #[allow(clippy::str_to_string, reason = "in macro invocation")]
    fn attrs(&self) -> Vec<quick_xml::events::attributes::Attribute> {
        let mut r = gen_attrs![b"baseFrequency":  format!("{} {}", self.base_frequency.0, self.base_frequency.1)];
        gen_attrs![
            r;
            self.num_octaves != 1 => b"numOctaves": self.num_octaves,
            self.seed != 0 => b"seed": self.seed,
            self.stitch_tiles != StitchTiles::NoStitch => b"stitchTiles": "stitch",
            self.noise_type != NoiseType::Turbulence => b"type": "fractalNoise"
        ];
        r
    }

    fn tag_name(&self) -> &'static str {
        "feTurbulence"
    }
}

#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum StitchTiles {
    Stitch,
    NoStitch,
}
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum NoiseType {
    Turbulence,
    FractalNoise,
}
