// @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, 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::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::types::value::Data;
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;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct LocationElsewhere<S: BosStr = DefaultStr> {
    #[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 LocationHome<S: BosStr = DefaultStr> {
    #[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 LocationMathTextbook<S: BosStr = DefaultStr> {
    #[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 LocationOnSkin<S: BosStr = DefaultStr> {
    #[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 LocationSchool<S: BosStr = DefaultStr> {
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Describes an instance of the user drawing the Delta Rune symbol from Undertale/Deltarune.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "download.darkworld.deltarune",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Deltarune<S: BosStr = DefaultStr> {
    pub time: Datetime,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tool: Option<DeltaruneTool<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub r#where: Option<DeltaruneWhere<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 DeltaruneTool<S: BosStr = DefaultStr> {
    #[serde(rename = "download.darkworld.deltarune#toolPen")]
    ToolPen(Box<deltarune::ToolPen<S>>),
    #[serde(rename = "download.darkworld.deltarune#toolPencil")]
    ToolPencil(Box<deltarune::ToolPencil<S>>),
    #[serde(rename = "download.darkworld.deltarune#toolMarker")]
    ToolMarker(Box<deltarune::ToolMarker<S>>),
    #[serde(rename = "download.darkworld.deltarune#toolFinger")]
    ToolFinger(Box<deltarune::ToolFinger<S>>),
    #[serde(rename = "download.darkworld.deltarune#toolOther")]
    ToolOther(Box<deltarune::ToolOther<S>>),
}


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

/// 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<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: Deltarune<S>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ToolFinger<S: BosStr = DefaultStr> {
    #[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 ToolMarker<S: BosStr = DefaultStr> {
    #[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 ToolOther<S: BosStr = DefaultStr> {
    #[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 ToolPen<S: BosStr = DefaultStr> {
    #[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 ToolPencil<S: BosStr = DefaultStr> {
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> Deltarune<S> {
    pub fn uri(uri: S) -> Result<RecordUri<S, DeltaruneRecord>, UriError> {
        RecordUri::try_from_uri(AtUri::new(uri)?)
    }
}

impl<S: BosStr> LexiconSchema for LocationElsewhere<S> {
    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<S: BosStr> LexiconSchema for LocationHome<S> {
    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<S: BosStr> LexiconSchema for LocationMathTextbook<S> {
    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<S: BosStr> LexiconSchema for LocationOnSkin<S> {
    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<S: BosStr> LexiconSchema for LocationSchool<S> {
    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<S: BosStr> = DeltaruneGetRecordOutput<S>;
    type Err = RecordError;
}

impl<S: BosStr> From<DeltaruneGetRecordOutput<S>> for Deltarune<S> {
    fn from(output: DeltaruneGetRecordOutput<S>) -> Self {
        output.value
    }
}

impl<S: BosStr> Collection for Deltarune<S> {
    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<S: BosStr> LexiconSchema for Deltarune<S> {
    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<S: BosStr> LexiconSchema for ToolFinger<S> {
    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<S: BosStr> LexiconSchema for ToolMarker<S> {
    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<S: BosStr> LexiconSchema for ToolOther<S> {
    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<S: BosStr> LexiconSchema for ToolPen<S> {
    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<S: BosStr> LexiconSchema for ToolPencil<S> {
    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<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetTime<St> {}
    impl<St: State> State for SetTime<St> {
        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<St: deltarune_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<Datetime>, Option<DeltaruneTool<S>>, Option<DeltaruneWhere<S>>),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

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

impl<St: deltarune_state::State, S: BosStr> DeltaruneBuilder<St, S> {
    /// Set the `tool` field (optional)
    pub fn tool(mut self, value: impl Into<Option<DeltaruneTool<S>>>) -> 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<S>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St: deltarune_state::State, S: BosStr> DeltaruneBuilder<St, S> {
    /// Set the `where` field (optional)
    pub fn r#where(mut self, value: impl Into<Option<DeltaruneWhere<S>>>) -> 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<S>>) -> Self {
        self._fields.2 = value;
        self
    }
}

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