use crate::validation::{Error, Validate};
use crate::{buffer, extensions, Index, Path, Root};
use serde_derive::{Deserialize, Serialize};
use shine_gltf_macro::Validate;
pub const VALID_MIME_TYPES: &[&str] = &["image/jpeg", "image/png"];
#[derive(Clone, Debug, Deserialize, Serialize, Validate)]
pub struct Image {
#[serde(rename = "bufferView")]
#[serde(skip_serializing_if = "Option::is_none")]
pub buffer_view: Option<Index<buffer::View>>,
#[serde(rename = "mimeType")]
#[serde(skip_serializing_if = "Option::is_none")]
pub mime_type: Option<MimeType>,
#[serde(skip_serializing_if = "Option::is_none")]
pub uri: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub extensions: Option<extensions::image::Image>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct MimeType(pub String);
impl Validate for MimeType {
fn validate_completely<P, R>(&self, _: &Root, path: P, report: &mut R)
where
P: Fn() -> Path,
R: FnMut(&dyn Fn() -> Path, Error),
{
if !VALID_MIME_TYPES.contains(&self.0.as_str()) {
report(&path, Error::Invalid);
}
}
}