// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: my.skylights.listItem
//
// 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::Datetime;
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::my_skylights::Item;
use crate::my_skylights::list::List;
use crate::my_skylights::list_item;
/// User gave up on finishing the item

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Hash)]
pub struct Abandoned;
impl core::fmt::Display for Abandoned {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "abandoned")
    }
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Builtin<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub r#type: Option<BuiltinType<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 BuiltinType<S: BosStr = DefaultStr> {
    #[serde(rename = "my.skylights.listItem#inProgress")]
    InProgress(Box<list_item::InProgress>),
    #[serde(rename = "my.skylights.listItem#queue")]
    Queue(Box<list_item::Queue>),
    #[serde(rename = "my.skylights.listItem#abandoned")]
    Abandoned(Box<list_item::Abandoned>),
    #[serde(rename = "my.skylights.listItem#owned")]
    Owned(Box<list_item::Owned>),
    #[serde(rename = "my.skylights.listItem#wishlist")]
    Wishlist(Box<list_item::Wishlist>),
}

/// User is currently reading/watching/... the item

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Hash)]
pub struct InProgress;
impl core::fmt::Display for InProgress {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "inProgress")
    }
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ListItem<S: BosStr = DefaultStr> {
    pub added_at: Datetime,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub item: Option<Item<S>>,
    pub list: ListItemList<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub note: Option<S>,
    pub position: 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 ListItemList<S: BosStr = DefaultStr> {
    #[serde(rename = "my.skylights.list")]
    List(Box<List<S>>),
    #[serde(rename = "my.skylights.listItem#builtin")]
    Builtin(Box<list_item::Builtin<S>>),
}

/// User owns the item

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Hash)]
pub struct Owned;
impl core::fmt::Display for Owned {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "owned")
    }
}

/// User plans to read/watch/... the item

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Hash)]
pub struct Queue;
impl core::fmt::Display for Queue {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "queue")
    }
}

/// User wants to own the item

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Hash)]
pub struct Wishlist;
impl core::fmt::Display for Wishlist {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "wishlist")
    }
}

impl<S: BosStr> LexiconSchema for Builtin<S> {
    fn nsid() -> &'static str {
        "my.skylights.listItem"
    }
    fn def_name() -> &'static str {
        "builtin"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_my_skylights_listItem()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for ListItem<S> {
    fn nsid() -> &'static str {
        "my.skylights.listItem"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_my_skylights_listItem()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

fn lexicon_doc_my_skylights_listItem() -> 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("my.skylights.listItem"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("abandoned"),
                LexUserType::Token(LexToken { ..Default::default() }),
            );
            map.insert(
                SmolStr::new_static("builtin"),
                LexUserType::Object(LexObject {
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("type"),
                            LexObjectProperty::Union(LexRefUnion {
                                refs: vec![
                                    CowStr::new_static("my.skylights.listItem#inProgress"),
                                    CowStr::new_static("my.skylights.listItem#queue"),
                                    CowStr::new_static("my.skylights.listItem#abandoned"),
                                    CowStr::new_static("my.skylights.listItem#owned"),
                                    CowStr::new_static("my.skylights.listItem#wishlist")
                                ],
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("inProgress"),
                LexUserType::Token(LexToken { ..Default::default() }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("list"), SmolStr::new_static("addedAt"),
                            SmolStr::new_static("position")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("addedAt"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("item"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("my.skylights.defs#item"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("list"),
                            LexObjectProperty::Union(LexRefUnion {
                                refs: vec![
                                    CowStr::new_static("my.skylights.list"),
                                    CowStr::new_static("#builtin")
                                ],
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("note"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("position"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("owned"),
                LexUserType::Token(LexToken { ..Default::default() }),
            );
            map.insert(
                SmolStr::new_static("queue"),
                LexUserType::Token(LexToken { ..Default::default() }),
            );
            map.insert(
                SmolStr::new_static("wishlist"),
                LexUserType::Token(LexToken { ..Default::default() }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod list_item_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 AddedAt;
        type List;
        type Position;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type AddedAt = Unset;
        type List = Unset;
        type Position = Unset;
    }
    ///State transition - sets the `added_at` field to Set
    pub struct SetAddedAt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetAddedAt<St> {}
    impl<St: State> State for SetAddedAt<St> {
        type AddedAt = Set<members::added_at>;
        type List = St::List;
        type Position = St::Position;
    }
    ///State transition - sets the `list` field to Set
    pub struct SetList<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetList<St> {}
    impl<St: State> State for SetList<St> {
        type AddedAt = St::AddedAt;
        type List = Set<members::list>;
        type Position = St::Position;
    }
    ///State transition - sets the `position` field to Set
    pub struct SetPosition<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetPosition<St> {}
    impl<St: State> State for SetPosition<St> {
        type AddedAt = St::AddedAt;
        type List = St::List;
        type Position = Set<members::position>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `added_at` field
        pub struct added_at(());
        ///Marker type for the `list` field
        pub struct list(());
        ///Marker type for the `position` field
        pub struct position(());
    }
}

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

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

impl<S: BosStr> ListItem<S> {
    /// Create a new builder for this type
    pub fn builder() -> ListItemBuilder<list_item_state::Empty, S> {
        ListItemBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> ListItemBuilder<St, S>
where
    St: list_item_state::State,
    St::AddedAt: list_item_state::IsUnset,
{
    /// Set the `addedAt` field (required)
    pub fn added_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> ListItemBuilder<list_item_state::SetAddedAt<St>, S> {
        self._fields.0 = Option::Some(value.into());
        ListItemBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St, S: BosStr> ListItemBuilder<St, S>
where
    St: list_item_state::State,
    St::List: list_item_state::IsUnset,
{
    /// Set the `list` field (required)
    pub fn list(
        mut self,
        value: impl Into<ListItemList<S>>,
    ) -> ListItemBuilder<list_item_state::SetList<St>, S> {
        self._fields.2 = Option::Some(value.into());
        ListItemBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: list_item_state::State, S: BosStr> ListItemBuilder<St, S> {
    /// Set the `note` field (optional)
    pub fn note(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `note` field to an Option value (optional)
    pub fn maybe_note(mut self, value: Option<S>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<St, S: BosStr> ListItemBuilder<St, S>
where
    St: list_item_state::State,
    St::Position: list_item_state::IsUnset,
{
    /// Set the `position` field (required)
    pub fn position(
        mut self,
        value: impl Into<S>,
    ) -> ListItemBuilder<list_item_state::SetPosition<St>, S> {
        self._fields.4 = Option::Some(value.into());
        ListItemBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ListItemBuilder<St, S>
where
    St: list_item_state::State,
    St::AddedAt: list_item_state::IsSet,
    St::List: list_item_state::IsSet,
    St::Position: list_item_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ListItem<S> {
        ListItem {
            added_at: self._fields.0.unwrap(),
            item: self._fields.1,
            list: self._fields.2.unwrap(),
            note: self._fields.3,
            position: self._fields.4.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>>) -> ListItem<S> {
        ListItem {
            added_at: self._fields.0.unwrap(),
            item: self._fields.1,
            list: self._fields.2.unwrap(),
            note: self._fields.3,
            position: self._fields.4.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}