// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: network.slices.tools.defs
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

pub mod bug;
pub mod document;
pub mod richtext;


#[allow(unused_imports)]
use alloc::collections::BTreeMap;

#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::blob::BlobRef;
use jacquard_derive::{IntoStatic, lexicon};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::network_slices::tools;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Image<'a> {
    ///Alt text description of the image, for accessibility
    #[serde(borrow)]
    pub alt: CowStr<'a>,
    #[serde(borrow)]
    pub image: BlobRef<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Images<'a> {
    #[serde(borrow)]
    pub images: Vec<tools::Image<'a>>,
}

impl<'a> LexiconSchema for Image<'a> {
    fn nsid() -> &'static str {
        "network.slices.tools.defs"
    }
    fn def_name() -> &'static str {
        "image"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_network_slices_tools_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.image;
            {
                let size = value.blob().size;
                if size > 1000000usize {
                    return Err(ConstraintError::BlobTooLarge {
                        path: ValidationPath::from_field("image"),
                        max: 1000000usize,
                        actual: size,
                    });
                }
            }
        }
        {
            let value = &self.image;
            {
                let mime = value.blob().mime_type.as_str();
                let accepted: &[&str] = &["image/*"];
                let matched = accepted
                    .iter()
                    .any(|pattern| {
                        if *pattern == "*/*" {
                            true
                        } else if pattern.ends_with("/*") {
                            let prefix = &pattern[..pattern.len() - 2];
                            mime.starts_with(prefix)
                                && mime.as_bytes().get(prefix.len()) == Some(&b'/')
                        } else {
                            mime == *pattern
                        }
                    });
                if !matched {
                    return Err(ConstraintError::BlobMimeTypeNotAccepted {
                        path: ValidationPath::from_field("image"),
                        accepted: vec!["image/*".to_string()],
                        actual: mime.to_string(),
                    });
                }
            }
        }
        Ok(())
    }
}

impl<'a> LexiconSchema for Images<'a> {
    fn nsid() -> &'static str {
        "network.slices.tools.defs"
    }
    fn def_name() -> &'static str {
        "images"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_network_slices_tools_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.images;
            #[allow(unused_comparisons)]
            if value.len() > 4usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("images"),
                    max: 4usize,
                    actual: value.len(),
                });
            }
        }
        Ok(())
    }
}

pub mod image_state {

    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
    #[allow(unused)]
    use ::core::marker::PhantomData;
    mod sealed {
        pub trait Sealed {}
    }
    /// State trait tracking which required fields have been set
    pub trait State: sealed::Sealed {
        type Image;
        type Alt;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Image = Unset;
        type Alt = Unset;
    }
    ///State transition - sets the `image` field to Set
    pub struct SetImage<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetImage<S> {}
    impl<S: State> State for SetImage<S> {
        type Image = Set<members::image>;
        type Alt = S::Alt;
    }
    ///State transition - sets the `alt` field to Set
    pub struct SetAlt<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetAlt<S> {}
    impl<S: State> State for SetAlt<S> {
        type Image = S::Image;
        type Alt = Set<members::alt>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `image` field
        pub struct image(());
        ///Marker type for the `alt` field
        pub struct alt(());
    }
}

/// Builder for constructing an instance of this type
pub struct ImageBuilder<'a, S: image_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<CowStr<'a>>, Option<BlobRef<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> Image<'a> {
    /// Create a new builder for this type
    pub fn new() -> ImageBuilder<'a, image_state::Empty> {
        ImageBuilder::new()
    }
}

impl<'a> ImageBuilder<'a, image_state::Empty> {
    /// Create a new builder with all fields unset
    pub fn new() -> Self {
        ImageBuilder {
            _state: PhantomData,
            _fields: (None, None),
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> ImageBuilder<'a, S>
where
    S: image_state::State,
    S::Alt: image_state::IsUnset,
{
    /// Set the `alt` field (required)
    pub fn alt(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> ImageBuilder<'a, image_state::SetAlt<S>> {
        self._fields.0 = Option::Some(value.into());
        ImageBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> ImageBuilder<'a, S>
where
    S: image_state::State,
    S::Image: image_state::IsUnset,
{
    /// Set the `image` field (required)
    pub fn image(
        mut self,
        value: impl Into<BlobRef<'a>>,
    ) -> ImageBuilder<'a, image_state::SetImage<S>> {
        self._fields.1 = Option::Some(value.into());
        ImageBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> ImageBuilder<'a, S>
where
    S: image_state::State,
    S::Image: image_state::IsSet,
    S::Alt: image_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Image<'a> {
        Image {
            alt: self._fields.0.unwrap(),
            image: self._fields.1.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Image<'a> {
        Image {
            alt: self._fields.0.unwrap(),
            image: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_network_slices_tools_defs() -> LexiconDoc<'static> {
    #[allow(unused_imports)]
    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
    use jacquard_lexicon::lexicon::*;
    use alloc::collections::BTreeMap;
    LexiconDoc {
        lexicon: Lexicon::Lexicon1,
        id: CowStr::new_static("network.slices.tools.defs"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("image"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("image"), SmolStr::new_static("alt")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("alt"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Alt text description of the image, for accessibility",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("image"),
                            LexObjectProperty::Blob(LexBlob { ..Default::default() }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("images"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("images")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("images"),
                            LexObjectProperty::Array(LexArray {
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("#image"),
                                    ..Default::default()
                                }),
                                max_length: Some(4usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod images_state {

    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
    #[allow(unused)]
    use ::core::marker::PhantomData;
    mod sealed {
        pub trait Sealed {}
    }
    /// State trait tracking which required fields have been set
    pub trait State: sealed::Sealed {
        type Images;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Images = Unset;
    }
    ///State transition - sets the `images` field to Set
    pub struct SetImages<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetImages<S> {}
    impl<S: State> State for SetImages<S> {
        type Images = Set<members::images>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `images` field
        pub struct images(());
    }
}

/// Builder for constructing an instance of this type
pub struct ImagesBuilder<'a, S: images_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<Vec<tools::Image<'a>>>,),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> Images<'a> {
    /// Create a new builder for this type
    pub fn new() -> ImagesBuilder<'a, images_state::Empty> {
        ImagesBuilder::new()
    }
}

impl<'a> ImagesBuilder<'a, images_state::Empty> {
    /// Create a new builder with all fields unset
    pub fn new() -> Self {
        ImagesBuilder {
            _state: PhantomData,
            _fields: (None,),
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> ImagesBuilder<'a, S>
where
    S: images_state::State,
    S::Images: images_state::IsUnset,
{
    /// Set the `images` field (required)
    pub fn images(
        mut self,
        value: impl Into<Vec<tools::Image<'a>>>,
    ) -> ImagesBuilder<'a, images_state::SetImages<S>> {
        self._fields.0 = Option::Some(value.into());
        ImagesBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> ImagesBuilder<'a, S>
where
    S: images_state::State,
    S::Images: images_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Images<'a> {
        Images {
            images: self._fields.0.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Images<'a> {
        Images {
            images: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}