// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: garden.lexicon.exultant-zebra.masl
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

#[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::garden_lexicon::exultant_zebra::masl;
/// A bundle of resources.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Masl<'a> {
    ///Optional name for the bundle.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub name: Option<CowStr<'a>>,
    ///The resources in this bundle.
    #[serde(borrow)]
    pub resources: Vec<masl::Resource<'a>>,
}

/// A single resource identified by a CID.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Resource<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub content_type: Option<CowStr<'a>>,
    ///Optional path for this resource (e.g. '/index.html').
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub path: Option<CowStr<'a>>,
    ///The content identifier for this resource.
    #[serde(borrow)]
    pub src: BlobRef<'a>,
}

impl<'a> LexiconSchema for Masl<'a> {
    fn nsid() -> &'static str {
        "garden.lexicon.exultant-zebra.masl"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_garden_lexicon_exultant_zebra_masl()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for Resource<'a> {
    fn nsid() -> &'static str {
        "garden.lexicon.exultant-zebra.masl"
    }
    fn def_name() -> &'static str {
        "resource"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_garden_lexicon_exultant_zebra_masl()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

pub mod masl_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 Resources;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Resources = Unset;
    }
    ///State transition - sets the `resources` field to Set
    pub struct SetResources<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetResources<S> {}
    impl<S: State> State for SetResources<S> {
        type Resources = Set<members::resources>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `resources` field
        pub struct resources(());
    }
}

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

impl<'a> Masl<'a> {
    /// Create a new builder for this type
    pub fn new() -> MaslBuilder<'a, masl_state::Empty> {
        MaslBuilder::new()
    }
}

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

impl<'a, S: masl_state::State> MaslBuilder<'a, S> {
    /// Set the `name` field (optional)
    pub fn name(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `name` field to an Option value (optional)
    pub fn maybe_name(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<'a, S> MaslBuilder<'a, S>
where
    S: masl_state::State,
    S::Resources: masl_state::IsUnset,
{
    /// Set the `resources` field (required)
    pub fn resources(
        mut self,
        value: impl Into<Vec<masl::Resource<'a>>>,
    ) -> MaslBuilder<'a, masl_state::SetResources<S>> {
        self._fields.1 = Option::Some(value.into());
        MaslBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> MaslBuilder<'a, S>
where
    S: masl_state::State,
    S::Resources: masl_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Masl<'a> {
        Masl {
            name: self._fields.0,
            resources: 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>,
        >,
    ) -> Masl<'a> {
        Masl {
            name: self._fields.0,
            resources: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_garden_lexicon_exultant_zebra_masl() -> 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("garden.lexicon.exultant-zebra.masl"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Object(LexObject {
                    description: Some(CowStr::new_static("A bundle of resources.")),
                    required: Some(vec![SmolStr::new_static("resources")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("name"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Optional name for the bundle."),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("resources"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static("The resources in this bundle."),
                                ),
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static(
                                        "garden.lexicon.exultant-zebra.masl#resource",
                                    ),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("resource"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("A single resource identified by a CID."),
                    ),
                    required: Some(vec![SmolStr::new_static("src")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("contentType"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("path"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Optional path for this resource (e.g. '/index.html').",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("src"),
                            LexObjectProperty::Blob(LexBlob { ..Default::default() }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod resource_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 Src;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Src = Unset;
    }
    ///State transition - sets the `src` field to Set
    pub struct SetSrc<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetSrc<S> {}
    impl<S: State> State for SetSrc<S> {
        type Src = Set<members::src>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `src` field
        pub struct src(());
    }
}

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

impl<'a> Resource<'a> {
    /// Create a new builder for this type
    pub fn new() -> ResourceBuilder<'a, resource_state::Empty> {
        ResourceBuilder::new()
    }
}

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

impl<'a, S: resource_state::State> ResourceBuilder<'a, S> {
    /// Set the `contentType` field (optional)
    pub fn content_type(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `contentType` field to an Option value (optional)
    pub fn maybe_content_type(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<'a, S: resource_state::State> ResourceBuilder<'a, S> {
    /// Set the `path` field (optional)
    pub fn path(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `path` field to an Option value (optional)
    pub fn maybe_path(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<'a, S> ResourceBuilder<'a, S>
where
    S: resource_state::State,
    S::Src: resource_state::IsUnset,
{
    /// Set the `src` field (required)
    pub fn src(
        mut self,
        value: impl Into<BlobRef<'a>>,
    ) -> ResourceBuilder<'a, resource_state::SetSrc<S>> {
        self._fields.2 = Option::Some(value.into());
        ResourceBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> ResourceBuilder<'a, S>
where
    S: resource_state::State,
    S::Src: resource_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Resource<'a> {
        Resource {
            content_type: self._fields.0,
            path: self._fields.1,
            src: self._fields.2.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>,
        >,
    ) -> Resource<'a> {
        Resource {
            content_type: self._fields.0,
            path: self._fields.1,
            src: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}