use crate::VoxelType;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BlockPalette {
    pub name: String,
    pub author: Option<String>,
    pub blocks: PaletteMappings,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PaletteMappings {
    pub body: String,
    pub outline: Option<String>,
    pub shadow: Option<String>,
}

impl BlockPalette {
    pub fn resolve(&self, voxel: &VoxelType) -> String {
        match voxel {
            VoxelType::Body => self.blocks.body.clone(),
            VoxelType::Outline => self
                .blocks
                .outline
                .clone()
                .unwrap_or_else(|| "minecraft:air".to_string()),
            VoxelType::Shadow => self
                .blocks
                .shadow
                .clone()
                .unwrap_or_else(|| "minecraft:air".to_string()),
        }
    }
}
