use serde::{Deserialize, Serialize};

use crate::ecs::material::components::{AlphaMode, Material, TextureTransform};

use super::asset_uuid::AssetUuid;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SceneMaterial {
    pub base_color: [f32; 4],
    pub emissive_factor: [f32; 3],
    #[serde(default)]
    pub alpha_mode: SceneAlphaMode,
    #[serde(default = "default_alpha_cutoff")]
    pub alpha_cutoff: f32,
    #[serde(default = "default_scene_blend_opaque_alpha_threshold")]
    pub blend_opaque_alpha_threshold: f32,
    #[serde(default)]
    pub base_texture_uuid: Option<AssetUuid>,
    #[serde(default)]
    pub base_texture_name: Option<String>,
    #[serde(default)]
    pub base_texture_transform: TextureTransform,
    #[serde(default)]
    pub emissive_texture_uuid: Option<AssetUuid>,
    #[serde(default)]
    pub emissive_texture_name: Option<String>,
    #[serde(default)]
    pub emissive_texture_transform: TextureTransform,
    #[serde(default)]
    pub normal_texture_uuid: Option<AssetUuid>,
    #[serde(default)]
    pub normal_texture_name: Option<String>,
    #[serde(default)]
    pub normal_texture_transform: TextureTransform,
    #[serde(default = "default_normal_scale")]
    pub normal_scale: f32,
    #[serde(default)]
    pub normal_map_flip_y: bool,
    #[serde(default)]
    pub normal_map_two_component: bool,
    #[serde(default)]
    pub metallic_roughness_texture_uuid: Option<AssetUuid>,
    #[serde(default)]
    pub metallic_roughness_texture_name: Option<String>,
    #[serde(default)]
    pub metallic_roughness_texture_transform: TextureTransform,
    #[serde(default)]
    pub occlusion_texture_uuid: Option<AssetUuid>,
    #[serde(default)]
    pub occlusion_texture_name: Option<String>,
    #[serde(default)]
    pub occlusion_texture_transform: TextureTransform,
    #[serde(default = "default_occlusion_strength")]
    pub occlusion_strength: f32,
    #[serde(default = "default_roughness")]
    pub roughness: f32,
    #[serde(default)]
    pub metallic: f32,
    #[serde(default)]
    pub unlit: bool,
    #[serde(default)]
    pub double_sided: bool,
    #[serde(default)]
    pub transmission_factor: f32,
    #[serde(default)]
    pub transmission_texture_uuid: Option<AssetUuid>,
    #[serde(default)]
    pub transmission_texture_name: Option<String>,
    #[serde(default)]
    pub transmission_texture_transform: TextureTransform,
    #[serde(default)]
    pub thickness: f32,
    #[serde(default)]
    pub thickness_texture_uuid: Option<AssetUuid>,
    #[serde(default)]
    pub thickness_texture_name: Option<String>,
    #[serde(default)]
    pub thickness_texture_transform: TextureTransform,
    #[serde(default = "default_attenuation_color")]
    pub attenuation_color: [f32; 3],
    #[serde(default = "default_attenuation_distance")]
    pub attenuation_distance: f32,
    #[serde(default = "default_ior")]
    pub ior: f32,
    #[serde(default = "default_specular_factor")]
    pub specular_factor: f32,
    #[serde(default = "default_specular_color_factor")]
    pub specular_color_factor: [f32; 3],
    #[serde(default)]
    pub specular_texture_uuid: Option<AssetUuid>,
    #[serde(default)]
    pub specular_texture_name: Option<String>,
    #[serde(default)]
    pub specular_texture_transform: TextureTransform,
    #[serde(default)]
    pub specular_color_texture_uuid: Option<AssetUuid>,
    #[serde(default)]
    pub specular_color_texture_name: Option<String>,
    #[serde(default)]
    pub specular_color_texture_transform: TextureTransform,
    #[serde(default = "default_emissive_strength")]
    pub emissive_strength: f32,
    #[serde(default)]
    pub diffuse_transmission_factor: f32,
    #[serde(default)]
    pub diffuse_transmission_texture_uuid: Option<AssetUuid>,
    #[serde(default)]
    pub diffuse_transmission_texture_name: Option<String>,
    #[serde(default)]
    pub diffuse_transmission_texture_transform: TextureTransform,
    #[serde(default = "default_diffuse_transmission_color")]
    pub diffuse_transmission_color_factor: [f32; 3],
    #[serde(default)]
    pub diffuse_transmission_color_texture_uuid: Option<AssetUuid>,
    #[serde(default)]
    pub diffuse_transmission_color_texture_name: Option<String>,
    #[serde(default)]
    pub diffuse_transmission_color_texture_transform: TextureTransform,
    #[serde(default)]
    pub dispersion: f32,
    #[serde(default)]
    pub anisotropy_strength: f32,
    #[serde(default)]
    pub anisotropy_rotation: f32,
    #[serde(default)]
    pub anisotropy_texture_uuid: Option<AssetUuid>,
    #[serde(default)]
    pub anisotropy_texture_name: Option<String>,
    #[serde(default)]
    pub anisotropy_texture_transform: TextureTransform,
    #[serde(default)]
    pub iridescence_factor: f32,
    #[serde(default)]
    pub iridescence_texture_uuid: Option<AssetUuid>,
    #[serde(default)]
    pub iridescence_texture_name: Option<String>,
    #[serde(default)]
    pub iridescence_texture_transform: TextureTransform,
    #[serde(default = "default_iridescence_ior")]
    pub iridescence_ior: f32,
    #[serde(default = "default_iridescence_thickness_min")]
    pub iridescence_thickness_minimum: f32,
    #[serde(default = "default_iridescence_thickness_max")]
    pub iridescence_thickness_maximum: f32,
    #[serde(default)]
    pub iridescence_thickness_texture_uuid: Option<AssetUuid>,
    #[serde(default)]
    pub iridescence_thickness_texture_name: Option<String>,
    #[serde(default)]
    pub iridescence_thickness_texture_transform: TextureTransform,
    #[serde(default)]
    pub sheen_color_factor: [f32; 3],
    #[serde(default)]
    pub sheen_color_texture_uuid: Option<AssetUuid>,
    #[serde(default)]
    pub sheen_color_texture_name: Option<String>,
    #[serde(default)]
    pub sheen_color_texture_transform: TextureTransform,
    #[serde(default)]
    pub sheen_roughness_factor: f32,
    #[serde(default)]
    pub sheen_roughness_texture_uuid: Option<AssetUuid>,
    #[serde(default)]
    pub sheen_roughness_texture_name: Option<String>,
    #[serde(default)]
    pub sheen_roughness_texture_transform: TextureTransform,
    #[serde(default)]
    pub clearcoat_factor: f32,
    #[serde(default)]
    pub clearcoat_texture_uuid: Option<AssetUuid>,
    #[serde(default)]
    pub clearcoat_texture_name: Option<String>,
    #[serde(default)]
    pub clearcoat_texture_transform: TextureTransform,
    #[serde(default)]
    pub clearcoat_roughness_factor: f32,
    #[serde(default)]
    pub clearcoat_roughness_texture_uuid: Option<AssetUuid>,
    #[serde(default)]
    pub clearcoat_roughness_texture_name: Option<String>,
    #[serde(default)]
    pub clearcoat_roughness_texture_transform: TextureTransform,
    #[serde(default)]
    pub clearcoat_normal_texture_uuid: Option<AssetUuid>,
    #[serde(default)]
    pub clearcoat_normal_texture_name: Option<String>,
    #[serde(default)]
    pub clearcoat_normal_texture_transform: TextureTransform,
    #[serde(default = "default_normal_scale")]
    pub clearcoat_normal_scale: f32,
}

fn default_alpha_cutoff() -> f32 {
    0.5
}

fn default_scene_blend_opaque_alpha_threshold() -> f32 {
    0.99
}

fn default_roughness() -> f32 {
    0.5
}

fn default_normal_scale() -> f32 {
    1.0
}

fn default_occlusion_strength() -> f32 {
    1.0
}

fn default_attenuation_color() -> [f32; 3] {
    [1.0, 1.0, 1.0]
}

fn default_attenuation_distance() -> f32 {
    f32::INFINITY
}

fn default_ior() -> f32 {
    1.5
}

fn default_specular_factor() -> f32 {
    1.0
}

fn default_specular_color_factor() -> [f32; 3] {
    [1.0, 1.0, 1.0]
}

fn default_emissive_strength() -> f32 {
    1.0
}

fn default_diffuse_transmission_color() -> [f32; 3] {
    [1.0, 1.0, 1.0]
}

fn default_iridescence_ior() -> f32 {
    1.3
}

fn default_iridescence_thickness_min() -> f32 {
    100.0
}

fn default_iridescence_thickness_max() -> f32 {
    400.0
}

impl Default for SceneMaterial {
    fn default() -> Self {
        Self {
            base_color: [1.0, 1.0, 1.0, 1.0],
            emissive_factor: [0.0, 0.0, 0.0],
            alpha_mode: SceneAlphaMode::Opaque,
            alpha_cutoff: 0.5,
            blend_opaque_alpha_threshold: 0.99,
            base_texture_uuid: None,
            base_texture_name: None,
            base_texture_transform: TextureTransform::IDENTITY,
            emissive_texture_uuid: None,
            emissive_texture_name: None,
            emissive_texture_transform: TextureTransform::IDENTITY,
            normal_texture_uuid: None,
            normal_texture_name: None,
            normal_texture_transform: TextureTransform::IDENTITY,
            normal_scale: 1.0,
            normal_map_flip_y: false,
            normal_map_two_component: false,
            metallic_roughness_texture_uuid: None,
            metallic_roughness_texture_name: None,
            metallic_roughness_texture_transform: TextureTransform::IDENTITY,
            occlusion_texture_uuid: None,
            occlusion_texture_name: None,
            occlusion_texture_transform: TextureTransform::IDENTITY,
            occlusion_strength: 1.0,
            roughness: 0.5,
            metallic: 0.0,
            unlit: false,
            double_sided: false,
            transmission_factor: 0.0,
            transmission_texture_uuid: None,
            transmission_texture_name: None,
            transmission_texture_transform: TextureTransform::IDENTITY,
            thickness: 0.0,
            thickness_texture_uuid: None,
            thickness_texture_name: None,
            thickness_texture_transform: TextureTransform::IDENTITY,
            attenuation_color: [1.0, 1.0, 1.0],
            attenuation_distance: f32::INFINITY,
            ior: 1.5,
            specular_factor: 1.0,
            specular_color_factor: [1.0, 1.0, 1.0],
            specular_texture_uuid: None,
            specular_texture_name: None,
            specular_texture_transform: TextureTransform::IDENTITY,
            specular_color_texture_uuid: None,
            specular_color_texture_name: None,
            specular_color_texture_transform: TextureTransform::IDENTITY,
            emissive_strength: 1.0,
            diffuse_transmission_factor: 0.0,
            diffuse_transmission_texture_uuid: None,
            diffuse_transmission_texture_name: None,
            diffuse_transmission_texture_transform: TextureTransform::IDENTITY,
            diffuse_transmission_color_factor: [1.0, 1.0, 1.0],
            diffuse_transmission_color_texture_uuid: None,
            diffuse_transmission_color_texture_name: None,
            diffuse_transmission_color_texture_transform: TextureTransform::IDENTITY,
            dispersion: 0.0,
            anisotropy_strength: 0.0,
            anisotropy_rotation: 0.0,
            anisotropy_texture_uuid: None,
            anisotropy_texture_name: None,
            anisotropy_texture_transform: TextureTransform::IDENTITY,
            iridescence_factor: 0.0,
            iridescence_texture_uuid: None,
            iridescence_texture_name: None,
            iridescence_texture_transform: TextureTransform::IDENTITY,
            iridescence_ior: 1.3,
            iridescence_thickness_minimum: 100.0,
            iridescence_thickness_maximum: 400.0,
            iridescence_thickness_texture_uuid: None,
            iridescence_thickness_texture_name: None,
            iridescence_thickness_texture_transform: TextureTransform::IDENTITY,
            sheen_color_factor: [0.0, 0.0, 0.0],
            sheen_color_texture_uuid: None,
            sheen_color_texture_name: None,
            sheen_color_texture_transform: TextureTransform::IDENTITY,
            sheen_roughness_factor: 0.0,
            sheen_roughness_texture_uuid: None,
            sheen_roughness_texture_name: None,
            sheen_roughness_texture_transform: TextureTransform::IDENTITY,
            clearcoat_factor: 0.0,
            clearcoat_texture_uuid: None,
            clearcoat_texture_name: None,
            clearcoat_texture_transform: TextureTransform::IDENTITY,
            clearcoat_roughness_factor: 0.0,
            clearcoat_roughness_texture_uuid: None,
            clearcoat_roughness_texture_name: None,
            clearcoat_roughness_texture_transform: TextureTransform::IDENTITY,
            clearcoat_normal_texture_uuid: None,
            clearcoat_normal_texture_name: None,
            clearcoat_normal_texture_transform: TextureTransform::IDENTITY,
            clearcoat_normal_scale: 1.0,
        }
    }
}

impl SceneMaterial {
    /// Iterates over every texture name this material references across
    /// all PBR slots. Used at save time to walk material refs and embed
    /// the referenced texture bytes into the scene.
    pub fn texture_names(&self) -> impl Iterator<Item = &str> {
        [
            self.base_texture_name.as_deref(),
            self.emissive_texture_name.as_deref(),
            self.normal_texture_name.as_deref(),
            self.metallic_roughness_texture_name.as_deref(),
            self.occlusion_texture_name.as_deref(),
            self.transmission_texture_name.as_deref(),
            self.thickness_texture_name.as_deref(),
            self.specular_texture_name.as_deref(),
            self.specular_color_texture_name.as_deref(),
            self.diffuse_transmission_texture_name.as_deref(),
            self.diffuse_transmission_color_texture_name.as_deref(),
            self.anisotropy_texture_name.as_deref(),
            self.iridescence_texture_name.as_deref(),
            self.iridescence_thickness_texture_name.as_deref(),
            self.sheen_color_texture_name.as_deref(),
            self.sheen_roughness_texture_name.as_deref(),
            self.clearcoat_texture_name.as_deref(),
            self.clearcoat_roughness_texture_name.as_deref(),
            self.clearcoat_normal_texture_name.as_deref(),
        ]
        .into_iter()
        .flatten()
    }

    pub fn to_material(&self) -> Material {
        Material {
            base_color: self.base_color,
            emissive_factor: self.emissive_factor,
            alpha_mode: self.alpha_mode.into(),
            alpha_cutoff: self.alpha_cutoff,
            blend_opaque_alpha_threshold: self.blend_opaque_alpha_threshold,
            base_texture: self.base_texture_name.clone(),
            base_texture_transform: self.base_texture_transform,
            emissive_texture: self.emissive_texture_name.clone(),
            emissive_texture_transform: self.emissive_texture_transform,
            normal_texture: self.normal_texture_name.clone(),
            normal_texture_transform: self.normal_texture_transform,
            normal_scale: self.normal_scale,
            normal_map_flip_y: self.normal_map_flip_y,
            normal_map_two_component: self.normal_map_two_component,
            metallic_roughness_texture: self.metallic_roughness_texture_name.clone(),
            metallic_roughness_texture_transform: self.metallic_roughness_texture_transform,
            occlusion_texture: self.occlusion_texture_name.clone(),
            occlusion_texture_transform: self.occlusion_texture_transform,
            occlusion_strength: self.occlusion_strength,
            roughness: self.roughness,
            metallic: self.metallic,
            unlit: self.unlit,
            double_sided: self.double_sided,
            transmission_factor: self.transmission_factor,
            transmission_texture: self.transmission_texture_name.clone(),
            transmission_texture_transform: self.transmission_texture_transform,
            thickness: self.thickness,
            thickness_texture: self.thickness_texture_name.clone(),
            thickness_texture_transform: self.thickness_texture_transform,
            attenuation_color: self.attenuation_color,
            attenuation_distance: self.attenuation_distance,
            ior: self.ior,
            specular_factor: self.specular_factor,
            specular_color_factor: self.specular_color_factor,
            specular_texture: self.specular_texture_name.clone(),
            specular_texture_transform: self.specular_texture_transform,
            specular_color_texture: self.specular_color_texture_name.clone(),
            specular_color_texture_transform: self.specular_color_texture_transform,
            emissive_strength: self.emissive_strength,
            diffuse_transmission_factor: self.diffuse_transmission_factor,
            diffuse_transmission_texture: self.diffuse_transmission_texture_name.clone(),
            diffuse_transmission_texture_transform: self.diffuse_transmission_texture_transform,
            diffuse_transmission_color_factor: self.diffuse_transmission_color_factor,
            diffuse_transmission_color_texture: self
                .diffuse_transmission_color_texture_name
                .clone(),
            diffuse_transmission_color_texture_transform: self
                .diffuse_transmission_color_texture_transform,
            dispersion: self.dispersion,
            anisotropy_strength: self.anisotropy_strength,
            anisotropy_rotation: self.anisotropy_rotation,
            anisotropy_texture: self.anisotropy_texture_name.clone(),
            anisotropy_texture_transform: self.anisotropy_texture_transform,
            iridescence_factor: self.iridescence_factor,
            iridescence_texture: self.iridescence_texture_name.clone(),
            iridescence_texture_transform: self.iridescence_texture_transform,
            iridescence_ior: self.iridescence_ior,
            iridescence_thickness_minimum: self.iridescence_thickness_minimum,
            iridescence_thickness_maximum: self.iridescence_thickness_maximum,
            iridescence_thickness_texture: self.iridescence_thickness_texture_name.clone(),
            iridescence_thickness_texture_transform: self.iridescence_thickness_texture_transform,
            sheen_color_factor: self.sheen_color_factor,
            sheen_color_texture: self.sheen_color_texture_name.clone(),
            sheen_color_texture_transform: self.sheen_color_texture_transform,
            sheen_roughness_factor: self.sheen_roughness_factor,
            sheen_roughness_texture: self.sheen_roughness_texture_name.clone(),
            sheen_roughness_texture_transform: self.sheen_roughness_texture_transform,
            clearcoat_factor: self.clearcoat_factor,
            clearcoat_texture: self.clearcoat_texture_name.clone(),
            clearcoat_texture_transform: self.clearcoat_texture_transform,
            clearcoat_roughness_factor: self.clearcoat_roughness_factor,
            clearcoat_roughness_texture: self.clearcoat_roughness_texture_name.clone(),
            clearcoat_roughness_texture_transform: self.clearcoat_roughness_texture_transform,
            clearcoat_normal_texture: self.clearcoat_normal_texture_name.clone(),
            clearcoat_normal_texture_transform: self.clearcoat_normal_texture_transform,
            clearcoat_normal_scale: self.clearcoat_normal_scale,
        }
    }
}

impl From<&Material> for SceneMaterial {
    fn from(material: &Material) -> Self {
        Self {
            base_color: material.base_color,
            emissive_factor: material.emissive_factor,
            alpha_mode: material.alpha_mode.into(),
            alpha_cutoff: material.alpha_cutoff,
            blend_opaque_alpha_threshold: material.blend_opaque_alpha_threshold,
            base_texture_uuid: None,
            base_texture_name: material.base_texture.clone(),
            base_texture_transform: material.base_texture_transform,
            emissive_texture_uuid: None,
            emissive_texture_name: material.emissive_texture.clone(),
            emissive_texture_transform: material.emissive_texture_transform,
            normal_texture_uuid: None,
            normal_texture_name: material.normal_texture.clone(),
            normal_texture_transform: material.normal_texture_transform,
            normal_scale: material.normal_scale,
            normal_map_flip_y: material.normal_map_flip_y,
            normal_map_two_component: material.normal_map_two_component,
            metallic_roughness_texture_uuid: None,
            metallic_roughness_texture_name: material.metallic_roughness_texture.clone(),
            metallic_roughness_texture_transform: material.metallic_roughness_texture_transform,
            occlusion_texture_uuid: None,
            occlusion_texture_name: material.occlusion_texture.clone(),
            occlusion_texture_transform: material.occlusion_texture_transform,
            occlusion_strength: material.occlusion_strength,
            roughness: material.roughness,
            metallic: material.metallic,
            unlit: material.unlit,
            double_sided: material.double_sided,
            transmission_factor: material.transmission_factor,
            transmission_texture_uuid: None,
            transmission_texture_name: material.transmission_texture.clone(),
            transmission_texture_transform: material.transmission_texture_transform,
            thickness: material.thickness,
            thickness_texture_uuid: None,
            thickness_texture_name: material.thickness_texture.clone(),
            thickness_texture_transform: material.thickness_texture_transform,
            attenuation_color: material.attenuation_color,
            attenuation_distance: material.attenuation_distance,
            ior: material.ior,
            specular_factor: material.specular_factor,
            specular_color_factor: material.specular_color_factor,
            specular_texture_uuid: None,
            specular_texture_name: material.specular_texture.clone(),
            specular_texture_transform: material.specular_texture_transform,
            specular_color_texture_uuid: None,
            specular_color_texture_name: material.specular_color_texture.clone(),
            specular_color_texture_transform: material.specular_color_texture_transform,
            emissive_strength: material.emissive_strength,
            diffuse_transmission_factor: material.diffuse_transmission_factor,
            diffuse_transmission_texture_uuid: None,
            diffuse_transmission_texture_name: material.diffuse_transmission_texture.clone(),
            diffuse_transmission_texture_transform: material.diffuse_transmission_texture_transform,
            diffuse_transmission_color_factor: material.diffuse_transmission_color_factor,
            diffuse_transmission_color_texture_uuid: None,
            diffuse_transmission_color_texture_name: material
                .diffuse_transmission_color_texture
                .clone(),
            diffuse_transmission_color_texture_transform: material
                .diffuse_transmission_color_texture_transform,
            dispersion: material.dispersion,
            anisotropy_strength: material.anisotropy_strength,
            anisotropy_rotation: material.anisotropy_rotation,
            anisotropy_texture_uuid: None,
            anisotropy_texture_name: material.anisotropy_texture.clone(),
            anisotropy_texture_transform: material.anisotropy_texture_transform,
            iridescence_factor: material.iridescence_factor,
            iridescence_texture_uuid: None,
            iridescence_texture_name: material.iridescence_texture.clone(),
            iridescence_texture_transform: material.iridescence_texture_transform,
            iridescence_ior: material.iridescence_ior,
            iridescence_thickness_minimum: material.iridescence_thickness_minimum,
            iridescence_thickness_maximum: material.iridescence_thickness_maximum,
            iridescence_thickness_texture_uuid: None,
            iridescence_thickness_texture_name: material.iridescence_thickness_texture.clone(),
            iridescence_thickness_texture_transform: material
                .iridescence_thickness_texture_transform,
            sheen_color_factor: material.sheen_color_factor,
            sheen_color_texture_uuid: None,
            sheen_color_texture_name: material.sheen_color_texture.clone(),
            sheen_color_texture_transform: material.sheen_color_texture_transform,
            sheen_roughness_factor: material.sheen_roughness_factor,
            sheen_roughness_texture_uuid: None,
            sheen_roughness_texture_name: material.sheen_roughness_texture.clone(),
            sheen_roughness_texture_transform: material.sheen_roughness_texture_transform,
            clearcoat_factor: material.clearcoat_factor,
            clearcoat_texture_uuid: None,
            clearcoat_texture_name: material.clearcoat_texture.clone(),
            clearcoat_texture_transform: material.clearcoat_texture_transform,
            clearcoat_roughness_factor: material.clearcoat_roughness_factor,
            clearcoat_roughness_texture_uuid: None,
            clearcoat_roughness_texture_name: material.clearcoat_roughness_texture.clone(),
            clearcoat_roughness_texture_transform: material.clearcoat_roughness_texture_transform,
            clearcoat_normal_texture_uuid: None,
            clearcoat_normal_texture_name: material.clearcoat_normal_texture.clone(),
            clearcoat_normal_texture_transform: material.clearcoat_normal_texture_transform,
            clearcoat_normal_scale: material.clearcoat_normal_scale,
        }
    }
}

#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq)]
pub enum SceneAlphaMode {
    #[default]
    Opaque,
    Mask,
    Blend,
}

impl From<AlphaMode> for SceneAlphaMode {
    fn from(mode: AlphaMode) -> Self {
        match mode {
            AlphaMode::Opaque => SceneAlphaMode::Opaque,
            AlphaMode::Mask => SceneAlphaMode::Mask,
            AlphaMode::Blend => SceneAlphaMode::Blend,
        }
    }
}

impl From<SceneAlphaMode> for AlphaMode {
    fn from(mode: SceneAlphaMode) -> Self {
        match mode {
            SceneAlphaMode::Opaque => AlphaMode::Opaque,
            SceneAlphaMode::Mask => AlphaMode::Mask,
            SceneAlphaMode::Blend => AlphaMode::Blend,
        }
    }
}
