// @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;

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::string::UriValue;
use jacquard_derive::{IntoStatic, lexicon, 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;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct MultiRefSys<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub ref_sys: Option<Vec<coord_ref_sys::SingleRefSys<'a>>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct RefSysByRef<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub epoch: Option<i64>,
    #[serde(borrow)]
    pub href: UriValue<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct RefSysCustom<'a> {
    ///Value should not be reference
    #[serde(borrow)]
    pub r#type: CowStr<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct RefSysSimpleRef<'a> {
    ///The value is either a URI or a CURIE.
    #[serde(borrow)]
    pub uri: CowStr<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct SingleRefSys<'a> {
    #[serde(borrow)]
    pub ref_sys: SingleRefSysRefSys<'a>,
}


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

impl<'a> LexiconSchema for MultiRefSys<'a> {
    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<'a> LexiconSchema for RefSysByRef<'a> {
    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<'a> LexiconSchema for RefSysCustom<'a> {
    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<'a> LexiconSchema for RefSysSimpleRef<'a> {
    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<'a> LexiconSchema for SingleRefSys<'a> {
    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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetHref<S> {}
    impl<S: State> State for SetHref<S> {
        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<'a, S: ref_sys_by_ref_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<i64>, Option<UriValue<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

impl<'a, S: ref_sys_by_ref_state::State> RefSysByRefBuilder<'a, 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<'a, S> RefSysByRefBuilder<'a, S>
where
    S: ref_sys_by_ref_state::State,
    S::Href: ref_sys_by_ref_state::IsUnset,
{
    /// Set the `href` field (required)
    pub fn href(
        mut self,
        value: impl Into<UriValue<'a>>,
    ) -> RefSysByRefBuilder<'a, ref_sys_by_ref_state::SetHref<S>> {
        self._fields.1 = Option::Some(value.into());
        RefSysByRefBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> RefSysByRefBuilder<'a, S>
where
    S: ref_sys_by_ref_state::State,
    S::Href: ref_sys_by_ref_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> RefSysByRef<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> RefSysByRef<'a> {
        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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetRefSys<S> {}
    impl<S: State> State for SetRefSys<S> {
        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<'a, S: single_ref_sys_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<SingleRefSysRefSys<'a>>,),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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