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

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::string::Datetime;
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::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")
    }
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct Builtin<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub r#type: Option<BuiltinType<'a>>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum BuiltinType<'a> {
    #[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")
    }
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ListItem<'a> {
    pub added_at: Datetime,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub item: Option<Item<'a>>,
    #[serde(borrow)]
    pub list: ListItemList<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub note: Option<CowStr<'a>>,
    #[serde(borrow)]
    pub position: CowStr<'a>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum ListItemList<'a> {
    #[serde(rename = "my.skylights.list")]
    List(Box<List<'a>>),
    #[serde(rename = "my.skylights.listItem#builtin")]
    Builtin(Box<list_item::Builtin<'a>>),
}

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

/// Builder for constructing an instance of this type
pub struct ListItemBuilder<'a, S: list_item_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<Datetime>,
        Option<Item<'a>>,
        Option<ListItemList<'a>>,
        Option<CowStr<'a>>,
        Option<CowStr<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

impl<'a, S: list_item_state::State> ListItemBuilder<'a, S> {
    /// Set the `item` field (optional)
    pub fn item(mut self, value: impl Into<Option<Item<'a>>>) -> 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<'a>>) -> Self {
        self._fields.1 = value;
        self
    }
}

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

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

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

impl<'a, S> ListItemBuilder<'a, S>
where
    S: list_item_state::State,
    S::List: list_item_state::IsSet,
    S::AddedAt: list_item_state::IsSet,
    S::Position: list_item_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> ListItem<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> ListItem<'a> {
        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),
        }
    }
}