// @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, BosStr, DefaultStr, FromStaticStr};

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::blob::BlobRef;
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
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.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Masl<S: BosStr = DefaultStr> {
    ///Optional name for the bundle.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<S>,
    ///The resources in this bundle.
    pub resources: Vec<masl::Resource<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// A single resource identified by a CID.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Resource<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub content_type: Option<S>,
    ///Optional path for this resource (e.g. '/index.html').
    #[serde(skip_serializing_if = "Option::is_none")]
    pub path: Option<S>,
    ///The content identifier for this resource.
    pub src: BlobRef<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> LexiconSchema for Masl<S> {
    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<S: BosStr> LexiconSchema for Resource<S> {
    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<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetResources<St> {}
    impl<St: State> State for SetResources<St> {
        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<St: masl_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<S>, Option<Vec<masl::Resource<S>>>),
    _type: PhantomData<fn() -> S>,
}

impl Masl<DefaultStr> {
    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
    pub fn new() -> MaslBuilder<masl_state::Empty, DefaultStr> {
        MaslBuilder::new()
    }
}

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

impl MaslBuilder<masl_state::Empty, DefaultStr> {
    /// Create a new builder with all fields unset, using the default string type, if needed
    pub fn new() -> Self {
        MaslBuilder {
            _state: PhantomData,
            _fields: (None, None),
            _type: PhantomData,
        }
    }
}

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

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

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

impl<St, S: BosStr> MaslBuilder<St, S>
where
    St: masl_state::State,
    St::Resources: masl_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Masl<S> {
        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<SmolStr, Data<S>>) -> Masl<S> {
        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<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetSrc<St> {}
    impl<St: State> State for SetSrc<St> {
        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<St: resource_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<S>, Option<S>, Option<BlobRef<S>>),
    _type: PhantomData<fn() -> S>,
}

impl Resource<DefaultStr> {
    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
    pub fn new() -> ResourceBuilder<resource_state::Empty, DefaultStr> {
        ResourceBuilder::new()
    }
}

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

impl ResourceBuilder<resource_state::Empty, DefaultStr> {
    /// Create a new builder with all fields unset, using the default string type, if needed
    pub fn new() -> Self {
        ResourceBuilder {
            _state: PhantomData,
            _fields: (None, None, None),
            _type: PhantomData,
        }
    }
}

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

impl<St: resource_state::State, S: BosStr> ResourceBuilder<St, S> {
    /// Set the `contentType` field (optional)
    pub fn content_type(mut self, value: impl Into<Option<S>>) -> 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<S>) -> Self {
        self._fields.0 = value;
        self
    }
}

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

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

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