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

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;

#[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::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.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Bookmark<'a> {
    ///A strong ref to the record to be bookmarked. Currently, only `app.bsky.feed.post` records are supported.
    #[serde(borrow)]
    pub subject: StrongRef<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct BookmarkView<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created_at: Option<Datetime>,
    #[serde(borrow)]
    pub item: BookmarkViewItem<'a>,
    ///A strong ref to the bookmarked record.
    #[serde(borrow)]
    pub subject: StrongRef<'a>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum BookmarkViewItem<'a> {
    #[serde(rename = "app.bsky.feed.defs#blockedPost")]
    BlockedPost(Box<BlockedPost<'a>>),
    #[serde(rename = "app.bsky.feed.defs#notFoundPost")]
    NotFoundPost(Box<NotFoundPost<'a>>),
    #[serde(rename = "app.bsky.feed.defs#postView")]
    PostView(Box<PostView<'a>>),
}

impl<'a> LexiconSchema for Bookmark<'a> {
    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<'a> LexiconSchema for BookmarkView<'a> {
    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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetSubject<S> {}
    impl<S: State> State for SetSubject<S> {
        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<'a, S: bookmark_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<StrongRef<'a>>,),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

impl<'a, S> BookmarkBuilder<'a, S>
where
    S: bookmark_state::State,
    S::Subject: bookmark_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Bookmark<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Bookmark<'a> {
        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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetItem<S> {}
    impl<S: State> State for SetItem<S> {
        type Item = Set<members::item>;
        type Subject = S::Subject;
    }
    ///State transition - sets the `subject` field to Set
    pub struct SetSubject<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetSubject<S> {}
    impl<S: State> State for SetSubject<S> {
        type Item = S::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<'a, S: bookmark_view_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<Datetime>, Option<BookmarkViewItem<'a>>, Option<StrongRef<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

impl<'a, S: bookmark_view_state::State> BookmarkViewBuilder<'a, 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<'a, S> BookmarkViewBuilder<'a, S>
where
    S: bookmark_view_state::State,
    S::Item: bookmark_view_state::IsUnset,
{
    /// Set the `item` field (required)
    pub fn item(
        mut self,
        value: impl Into<BookmarkViewItem<'a>>,
    ) -> BookmarkViewBuilder<'a, bookmark_view_state::SetItem<S>> {
        self._fields.1 = Option::Some(value.into());
        BookmarkViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

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

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