// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: download.darkworld.deltarune
//
// 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::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::xrpc::XrpcResp;
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::download_darkworld::deltarune;

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

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

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

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

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct LocationSchool<'a> {}
/// Describes an instance of the user drawing the Delta Rune symbol from Undertale/Deltarune.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Deltarune<'a> {
    pub time: Datetime,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub tool: Option<DeltaruneTool<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub r#where: Option<DeltaruneWhere<'a>>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum DeltaruneTool<'a> {
    #[serde(rename = "download.darkworld.deltarune#toolPen")]
    ToolPen(Box<deltarune::ToolPen<'a>>),
    #[serde(rename = "download.darkworld.deltarune#toolPencil")]
    ToolPencil(Box<deltarune::ToolPencil<'a>>),
    #[serde(rename = "download.darkworld.deltarune#toolMarker")]
    ToolMarker(Box<deltarune::ToolMarker<'a>>),
    #[serde(rename = "download.darkworld.deltarune#toolFinger")]
    ToolFinger(Box<deltarune::ToolFinger<'a>>),
    #[serde(rename = "download.darkworld.deltarune#toolOther")]
    ToolOther(Box<deltarune::ToolOther<'a>>),
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum DeltaruneWhere<'a> {
    #[serde(rename = "download.darkworld.deltarune#locationSchool")]
    LocationSchool(Box<deltarune::LocationSchool<'a>>),
    #[serde(rename = "download.darkworld.deltarune#locationHome")]
    LocationHome(Box<deltarune::LocationHome<'a>>),
    #[serde(rename = "download.darkworld.deltarune#locationMathTextbook")]
    LocationMathTextbook(Box<deltarune::LocationMathTextbook<'a>>),
    #[serde(rename = "download.darkworld.deltarune#locationOnSkin")]
    LocationOnSkin(Box<deltarune::LocationOnSkin<'a>>),
    #[serde(rename = "download.darkworld.deltarune#locationElsewhere")]
    LocationElsewhere(Box<deltarune::LocationElsewhere<'a>>),
}

/// Typed wrapper for GetRecord response with this collection's record type.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct DeltaruneGetRecordOutput<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cid: Option<Cid<'a>>,
    #[serde(borrow)]
    pub uri: AtUri<'a>,
    #[serde(borrow)]
    pub value: Deltarune<'a>,
}


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

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

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

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

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct ToolPencil<'a> {}
impl<'a> Deltarune<'a> {
    pub fn uri(
        uri: impl Into<CowStr<'a>>,
    ) -> Result<RecordUri<'a, DeltaruneRecord>, UriError> {
        RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
    }
}

impl<'a> LexiconSchema for LocationElsewhere<'a> {
    fn nsid() -> &'static str {
        "download.darkworld.deltarune"
    }
    fn def_name() -> &'static str {
        "locationElsewhere"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_download_darkworld_deltarune()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for LocationHome<'a> {
    fn nsid() -> &'static str {
        "download.darkworld.deltarune"
    }
    fn def_name() -> &'static str {
        "locationHome"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_download_darkworld_deltarune()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for LocationMathTextbook<'a> {
    fn nsid() -> &'static str {
        "download.darkworld.deltarune"
    }
    fn def_name() -> &'static str {
        "locationMathTextbook"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_download_darkworld_deltarune()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for LocationOnSkin<'a> {
    fn nsid() -> &'static str {
        "download.darkworld.deltarune"
    }
    fn def_name() -> &'static str {
        "locationOnSkin"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_download_darkworld_deltarune()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for LocationSchool<'a> {
    fn nsid() -> &'static str {
        "download.darkworld.deltarune"
    }
    fn def_name() -> &'static str {
        "locationSchool"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_download_darkworld_deltarune()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

/// Marker type for deserializing records from this collection.

#[derive(Debug, Serialize, Deserialize)]
pub struct DeltaruneRecord;
impl XrpcResp for DeltaruneRecord {
    const NSID: &'static str = "download.darkworld.deltarune";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = DeltaruneGetRecordOutput<'de>;
    type Err<'de> = RecordError<'de>;
}

impl From<DeltaruneGetRecordOutput<'_>> for Deltarune<'_> {
    fn from(output: DeltaruneGetRecordOutput<'_>) -> Self {
        use jacquard_common::IntoStatic;
        output.value.into_static()
    }
}

impl Collection for Deltarune<'_> {
    const NSID: &'static str = "download.darkworld.deltarune";
    type Record = DeltaruneRecord;
}

impl Collection for DeltaruneRecord {
    const NSID: &'static str = "download.darkworld.deltarune";
    type Record = DeltaruneRecord;
}

impl<'a> LexiconSchema for Deltarune<'a> {
    fn nsid() -> &'static str {
        "download.darkworld.deltarune"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_download_darkworld_deltarune()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for ToolFinger<'a> {
    fn nsid() -> &'static str {
        "download.darkworld.deltarune"
    }
    fn def_name() -> &'static str {
        "toolFinger"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_download_darkworld_deltarune()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for ToolMarker<'a> {
    fn nsid() -> &'static str {
        "download.darkworld.deltarune"
    }
    fn def_name() -> &'static str {
        "toolMarker"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_download_darkworld_deltarune()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for ToolOther<'a> {
    fn nsid() -> &'static str {
        "download.darkworld.deltarune"
    }
    fn def_name() -> &'static str {
        "toolOther"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_download_darkworld_deltarune()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for ToolPen<'a> {
    fn nsid() -> &'static str {
        "download.darkworld.deltarune"
    }
    fn def_name() -> &'static str {
        "toolPen"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_download_darkworld_deltarune()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for ToolPencil<'a> {
    fn nsid() -> &'static str {
        "download.darkworld.deltarune"
    }
    fn def_name() -> &'static str {
        "toolPencil"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_download_darkworld_deltarune()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

fn lexicon_doc_download_darkworld_deltarune() -> 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("download.darkworld.deltarune"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("locationElsewhere"),
                LexUserType::Object(LexObject {
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("locationHome"),
                LexUserType::Object(LexObject {
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("locationMathTextbook"),
                LexUserType::Object(LexObject {
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("locationOnSkin"),
                LexUserType::Object(LexObject {
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("locationSchool"),
                LexUserType::Object(LexObject {
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "Describes an instance of the user drawing the Delta Rune symbol from Undertale/Deltarune.",
                        ),
                    ),
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(vec![SmolStr::new_static("time")]),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("time"),
                                LexObjectProperty::String(LexString {
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("tool"),
                                LexObjectProperty::Union(LexRefUnion {
                                    refs: vec![
                                        CowStr::new_static("#toolPen"),
                                        CowStr::new_static("#toolPencil"),
                                        CowStr::new_static("#toolMarker"),
                                        CowStr::new_static("#toolFinger"),
                                        CowStr::new_static("#toolOther")
                                    ],
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("where"),
                                LexObjectProperty::Union(LexRefUnion {
                                    refs: vec![
                                        CowStr::new_static("#locationSchool"),
                                        CowStr::new_static("#locationHome"),
                                        CowStr::new_static("#locationMathTextbook"),
                                        CowStr::new_static("#locationOnSkin"),
                                        CowStr::new_static("#locationElsewhere")
                                    ],
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("toolFinger"),
                LexUserType::Object(LexObject {
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("toolMarker"),
                LexUserType::Object(LexObject {
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("toolOther"),
                LexUserType::Object(LexObject {
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("toolPen"),
                LexUserType::Object(LexObject {
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("toolPencil"),
                LexUserType::Object(LexObject {
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

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

/// Builder for constructing an instance of this type
pub struct DeltaruneBuilder<'a, S: deltarune_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<Datetime>, Option<DeltaruneTool<'a>>, Option<DeltaruneWhere<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> Deltarune<'a> {
    /// Create a new builder for this type
    pub fn new() -> DeltaruneBuilder<'a, deltarune_state::Empty> {
        DeltaruneBuilder::new()
    }
}

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

impl<'a, S> DeltaruneBuilder<'a, S>
where
    S: deltarune_state::State,
    S::Time: deltarune_state::IsUnset,
{
    /// Set the `time` field (required)
    pub fn time(
        mut self,
        value: impl Into<Datetime>,
    ) -> DeltaruneBuilder<'a, deltarune_state::SetTime<S>> {
        self._fields.0 = Option::Some(value.into());
        DeltaruneBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: deltarune_state::State> DeltaruneBuilder<'a, S> {
    /// Set the `tool` field (optional)
    pub fn tool(mut self, value: impl Into<Option<DeltaruneTool<'a>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `tool` field to an Option value (optional)
    pub fn maybe_tool(mut self, value: Option<DeltaruneTool<'a>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<'a, S: deltarune_state::State> DeltaruneBuilder<'a, S> {
    /// Set the `where` field (optional)
    pub fn r#where(mut self, value: impl Into<Option<DeltaruneWhere<'a>>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `where` field to an Option value (optional)
    pub fn maybe_where(mut self, value: Option<DeltaruneWhere<'a>>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<'a, S> DeltaruneBuilder<'a, S>
where
    S: deltarune_state::State,
    S::Time: deltarune_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Deltarune<'a> {
        Deltarune {
            time: self._fields.0.unwrap(),
            tool: self._fields.1,
            r#where: self._fields.2,
            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>,
        >,
    ) -> Deltarune<'a> {
        Deltarune {
            time: self._fields.0.unwrap(),
            tool: self._fields.1,
            r#where: self._fields.2,
            extra_data: Some(extra_data),
        }
    }
}