// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: app.bsky.bookmark.defs
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

//! Generated bindings for the `app.bsky.bookmark` Lexicon namespace/module.
pub mod create_bookmark;
pub mod delete_bookmark;
pub mod get_bookmarks;


#[allow(unused_imports)]
use alloc::collections::BTreeMap;

#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{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::app_bsky::feed::BlockedPost;
use crate::app_bsky::feed::NotFoundPost;
use crate::app_bsky::feed::PostView;
use crate::com_atproto::repo::strong_ref::StrongRef;
/// Object used to store bookmark data in stash.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Bookmark<S: BosStr = DefaultStr> {
    ///A strong ref to the record to be bookmarked. Currently, only `app.bsky.feed.post` records are supported.
    pub subject: StrongRef<S>,
    #[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)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct BookmarkView<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created_at: Option<Datetime>,
    pub item: BookmarkViewItem<S>,
    ///A strong ref to the bookmarked record.
    pub subject: StrongRef<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 BookmarkViewItem<S: BosStr = DefaultStr> {
    #[serde(rename = "app.bsky.feed.defs#blockedPost")]
    BlockedPost(Box<BlockedPost<S>>),
    #[serde(rename = "app.bsky.feed.defs#notFoundPost")]
    NotFoundPost(Box<NotFoundPost<S>>),
    #[serde(rename = "app.bsky.feed.defs#postView")]
    PostView(Box<PostView<S>>),
}

impl<S: BosStr> LexiconSchema for Bookmark<S> {
    fn nsid() -> &'static str {
        "app.bsky.bookmark.defs"
    }
    fn def_name() -> &'static str {
        "bookmark"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_bsky_bookmark_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for BookmarkView<S> {
    fn nsid() -> &'static str {
        "app.bsky.bookmark.defs"
    }
    fn def_name() -> &'static str {
        "bookmarkView"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_bsky_bookmark_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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

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

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

impl<S: BosStr> Bookmark<S> {
    /// Create a new builder for this type
    pub fn builder() -> BookmarkBuilder<bookmark_state::Empty, S> {
        BookmarkBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> BookmarkBuilder<St, S>
where
    St: bookmark_state::State,
    St::Subject: bookmark_state::IsUnset,
{
    /// Set the `subject` field (required)
    pub fn subject(
        mut self,
        value: impl Into<StrongRef<S>>,
    ) -> BookmarkBuilder<bookmark_state::SetSubject<St>, S> {
        self._fields.0 = Option::Some(value.into());
        BookmarkBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> BookmarkBuilder<St, S>
where
    St: bookmark_state::State,
    St::Subject: bookmark_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Bookmark<S> {
        Bookmark {
            subject: 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<SmolStr, Data<S>>) -> Bookmark<S> {
        Bookmark {
            subject: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_app_bsky_bookmark_defs() -> 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("app.bsky.bookmark.defs"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("bookmark"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Object used to store bookmark data in stash.",
                        ),
                    ),
                    required: Some(vec![SmolStr::new_static("subject")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("subject"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("bookmarkView"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("subject"), SmolStr::new_static("item")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("createdAt"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("item"),
                            LexObjectProperty::Union(LexRefUnion {
                                refs: vec![
                                    CowStr::new_static("app.bsky.feed.defs#blockedPost"),
                                    CowStr::new_static("app.bsky.feed.defs#notFoundPost"),
                                    CowStr::new_static("app.bsky.feed.defs#postView")
                                ],
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("subject"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod bookmark_view_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 Item;
        type Subject;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Item = Unset;
        type Subject = Unset;
    }
    ///State transition - sets the `item` field to Set
    pub struct SetItem<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetItem<St> {}
    impl<St: State> State for SetItem<St> {
        type Item = Set<members::item>;
        type Subject = St::Subject;
    }
    ///State transition - sets the `subject` field to Set
    pub struct SetSubject<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetSubject<St> {}
    impl<St: State> State for SetSubject<St> {
        type Item = St::Item;
        type Subject = Set<members::subject>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `item` field
        pub struct item(());
        ///Marker type for the `subject` field
        pub struct subject(());
    }
}

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

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

impl<S: BosStr> BookmarkView<S> {
    /// Create a new builder for this type
    pub fn builder() -> BookmarkViewBuilder<bookmark_view_state::Empty, S> {
        BookmarkViewBuilder::builder()
    }
}

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

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

impl<St: bookmark_view_state::State, S: BosStr> BookmarkViewBuilder<St, S> {
    /// Set the `createdAt` field (optional)
    pub fn created_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `createdAt` field to an Option value (optional)
    pub fn maybe_created_at(mut self, value: Option<Datetime>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St, S: BosStr> BookmarkViewBuilder<St, S>
where
    St: bookmark_view_state::State,
    St::Item: bookmark_view_state::IsUnset,
{
    /// Set the `item` field (required)
    pub fn item(
        mut self,
        value: impl Into<BookmarkViewItem<S>>,
    ) -> BookmarkViewBuilder<bookmark_view_state::SetItem<St>, S> {
        self._fields.1 = Option::Some(value.into());
        BookmarkViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> BookmarkViewBuilder<St, S>
where
    St: bookmark_view_state::State,
    St::Subject: bookmark_view_state::IsUnset,
{
    /// Set the `subject` field (required)
    pub fn subject(
        mut self,
        value: impl Into<StrongRef<S>>,
    ) -> BookmarkViewBuilder<bookmark_view_state::SetSubject<St>, S> {
        self._fields.2 = Option::Some(value.into());
        BookmarkViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> BookmarkViewBuilder<St, S>
where
    St: bookmark_view_state::State,
    St::Item: bookmark_view_state::IsSet,
    St::Subject: bookmark_view_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> BookmarkView<S> {
        BookmarkView {
            created_at: self._fields.0,
            item: self._fields.1.unwrap(),
            subject: self._fields.2.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>>,
    ) -> BookmarkView<S> {
        BookmarkView {
            created_at: self._fields.0,
            item: self._fields.1.unwrap(),
            subject: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}