use block_mesh::Voxel;
use rand::distributions::{Distribution, Standard};

#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, bytemuck::Zeroable, bytemuck::Pod)]
pub struct VoxelColor {
    pub r: u8,
    pub g: u8,
    pub b: u8,
    pub a: u8,
}

impl VoxelColor {
    pub fn none() -> Self {
        Self {
            r: 0,
            g: 0,
            b: 0,
            a: 0,
        }
    }
    pub fn black() -> Self {
        Self {
            r: 0,
            g: 0,
            b: 0,
            a: 255,
        }
    }
    pub fn white() -> Self {
        Self {
            r: 255,
            g: 255,
            b: 255,
            a: 255,
        }
    }
}

impl Distribution<VoxelColor> for Standard {
    fn sample<R: rand::prelude::Rng + ?Sized>(&self, rng: &mut R) -> VoxelColor {
        VoxelColor {
            r: rng.gen(),
            g: rng.gen(),
            b: rng.gen(),
            a: rng.gen(),
        }
    }
}

impl block_mesh::Voxel for VoxelColor {
    fn get_visibility(&self) -> block_mesh::VoxelVisibility {
        match self.a {
            0 => block_mesh::VoxelVisibility::Empty,
            255 => block_mesh::VoxelVisibility::Opaque,
            _ => block_mesh::VoxelVisibility::Translucent,
        }
    }
}
