// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: org.custorium.temp.jsonfg.coordRefSys
//
// 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::string::UriValue;
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, open_union};
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::org_custorium::temp::jsonfg::coord_ref_sys;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct MultiRefSys<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ref_sys: Option<Vec<coord_ref_sys::SingleRefSys<S>>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct RefSysByRef<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub epoch: Option<i64>,
    pub href: UriValue<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct RefSysCustom<S: BosStr = DefaultStr> {
    ///Value should not be reference
    pub r#type: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct RefSysSimpleRef<S: BosStr = DefaultStr> {
    ///The value is either a URI or a CURIE.
    pub uri: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct SingleRefSys<S: BosStr = DefaultStr> {
    pub ref_sys: SingleRefSysRefSys<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum SingleRefSysRefSys<S: BosStr = DefaultStr> {
    #[serde(rename = "org.custorium.temp.jsonfg.coordRefSys#refSysSimpleRef")]
    RefSysSimpleRef(Box<coord_ref_sys::RefSysSimpleRef<S>>),
    #[serde(rename = "org.custorium.temp.jsonfg.coordRefSys#refSysByRef")]
    RefSysByRef(Box<coord_ref_sys::RefSysByRef<S>>),
    #[serde(rename = "org.custorium.temp.jsonfg.coordRefSys#refSysCustom")]
    RefSysCustom(Box<coord_ref_sys::RefSysCustom<S>>),
}

impl<S: BosStr> LexiconSchema for MultiRefSys<S> {
    fn nsid() -> &'static str {
        "org.custorium.temp.jsonfg.coordRefSys"
    }
    fn def_name() -> &'static str {
        "multiRefSys"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_org_custorium_temp_jsonfg_coordRefSys()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.ref_sys {
            #[allow(unused_comparisons)]
            if value.len() < 2usize {
                return Err(ConstraintError::MinLength {
                    path: ValidationPath::from_field("ref_sys"),
                    min: 2usize,
                    actual: value.len(),
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for RefSysByRef<S> {
    fn nsid() -> &'static str {
        "org.custorium.temp.jsonfg.coordRefSys"
    }
    fn def_name() -> &'static str {
        "refSysByRef"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_org_custorium_temp_jsonfg_coordRefSys()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for RefSysCustom<S> {
    fn nsid() -> &'static str {
        "org.custorium.temp.jsonfg.coordRefSys"
    }
    fn def_name() -> &'static str {
        "refSysCustom"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_org_custorium_temp_jsonfg_coordRefSys()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for RefSysSimpleRef<S> {
    fn nsid() -> &'static str {
        "org.custorium.temp.jsonfg.coordRefSys"
    }
    fn def_name() -> &'static str {
        "refSysSimpleRef"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_org_custorium_temp_jsonfg_coordRefSys()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for SingleRefSys<S> {
    fn nsid() -> &'static str {
        "org.custorium.temp.jsonfg.coordRefSys"
    }
    fn def_name() -> &'static str {
        "singleRefSys"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_org_custorium_temp_jsonfg_coordRefSys()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

fn lexicon_doc_org_custorium_temp_jsonfg_coordRefSys() -> 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("org.custorium.temp.jsonfg.coordRefSys"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("multiRefSys"),
                LexUserType::Object(LexObject {
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("refSys"),
                            LexObjectProperty::Array(LexArray {
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("#singleRefSys"),
                                    ..Default::default()
                                }),
                                min_length: Some(2usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("refSysByRef"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("href")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("epoch"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("href"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Uri),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("refSysCustom"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("type")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("type"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Value should not be reference"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("refSysSimpleRef"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("uri")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("uri"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The value is either a URI or a CURIE."),
                                ),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("singleRefSys"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("refSys")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("refSys"),
                            LexObjectProperty::Union(LexRefUnion {
                                refs: vec![
                                    CowStr::new_static("#refSysSimpleRef"),
                                    CowStr::new_static("#refSysByRef"),
                                    CowStr::new_static("#refSysCustom")
                                ],
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

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

/// Builder for constructing an instance of this type.
pub struct RefSysByRefBuilder<St: ref_sys_by_ref_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<i64>, Option<UriValue<S>>),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> RefSysByRef<S> {
    /// Create a new builder for this type
    pub fn builder() -> RefSysByRefBuilder<ref_sys_by_ref_state::Empty, S> {
        RefSysByRefBuilder::builder()
    }
}

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

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

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

impl<St, S: BosStr> RefSysByRefBuilder<St, S>
where
    St: ref_sys_by_ref_state::State,
    St::Href: ref_sys_by_ref_state::IsUnset,
{
    /// Set the `href` field (required)
    pub fn href(
        mut self,
        value: impl Into<UriValue<S>>,
    ) -> RefSysByRefBuilder<ref_sys_by_ref_state::SetHref<St>, S> {
        self._fields.1 = Option::Some(value.into());
        RefSysByRefBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> RefSysByRefBuilder<St, S>
where
    St: ref_sys_by_ref_state::State,
    St::Href: ref_sys_by_ref_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> RefSysByRef<S> {
        RefSysByRef {
            epoch: self._fields.0,
            href: 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>>,
    ) -> RefSysByRef<S> {
        RefSysByRef {
            epoch: self._fields.0,
            href: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

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

/// Builder for constructing an instance of this type.
pub struct SingleRefSysBuilder<St: single_ref_sys_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<SingleRefSysRefSys<S>>,),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> SingleRefSys<S> {
    /// Create a new builder for this type
    pub fn builder() -> SingleRefSysBuilder<single_ref_sys_state::Empty, S> {
        SingleRefSysBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> SingleRefSysBuilder<St, S>
where
    St: single_ref_sys_state::State,
    St::RefSys: single_ref_sys_state::IsUnset,
{
    /// Set the `refSys` field (required)
    pub fn ref_sys(
        mut self,
        value: impl Into<SingleRefSysRefSys<S>>,
    ) -> SingleRefSysBuilder<single_ref_sys_state::SetRefSys<St>, S> {
        self._fields.0 = Option::Some(value.into());
        SingleRefSysBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> SingleRefSysBuilder<St, S>
where
    St: single_ref_sys_state::State,
    St::RefSys: single_ref_sys_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> SingleRefSys<S> {
        SingleRefSys {
            ref_sys: 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<SmolStr, Data<S>>,
    ) -> SingleRefSys<S> {
        SingleRefSys {
            ref_sys: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}