// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: sh.weaver.notebook.authors
//
// 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::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime};
use jacquard_common::types::uri::{RecordUri, UriError};
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::app_bsky::actor::ProfileViewBasic;
use crate::sh_weaver::actor::ProfileView;
use crate::sh_weaver::notebook::authors;
/// A single author in a Weaver notebook.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct AuthorListItem<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub index: Option<i64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub profile: Option<AuthorListItemProfile<'a>>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum AuthorListItemProfile<'a> {
    #[serde(rename = "app.bsky.actor.defs#profileViewBasic")]
    ProfileViewBasic(Box<ProfileViewBasic<'a>>),
    #[serde(rename = "sh.weaver.actor.defs#profileView")]
    ProfileView(Box<ProfileView<'a>>),
}

/// Authors of a Weaver notebook.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Authors<'a> {
    #[serde(borrow)]
    pub author_list: Vec<authors::AuthorListItem<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created_at: Option<Datetime>,
}

/// 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 AuthorsGetRecordOutput<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cid: Option<Cid<'a>>,
    #[serde(borrow)]
    pub uri: AtUri<'a>,
    #[serde(borrow)]
    pub value: Authors<'a>,
}

impl<'a> Authors<'a> {
    pub fn uri(
        uri: impl Into<CowStr<'a>>,
    ) -> Result<RecordUri<'a, AuthorsRecord>, UriError> {
        RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
    }
}

impl<'a> LexiconSchema for AuthorListItem<'a> {
    fn nsid() -> &'static str {
        "sh.weaver.notebook.authors"
    }
    fn def_name() -> &'static str {
        "authorListItem"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_weaver_notebook_authors()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

/// Marker type for deserializing records from this collection.

#[derive(Debug, Serialize, Deserialize)]
pub struct AuthorsRecord;
impl XrpcResp for AuthorsRecord {
    const NSID: &'static str = "sh.weaver.notebook.authors";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = AuthorsGetRecordOutput<'de>;
    type Err<'de> = RecordError<'de>;
}

impl From<AuthorsGetRecordOutput<'_>> for Authors<'_> {
    fn from(output: AuthorsGetRecordOutput<'_>) -> Self {
        use jacquard_common::IntoStatic;
        output.value.into_static()
    }
}

impl Collection for Authors<'_> {
    const NSID: &'static str = "sh.weaver.notebook.authors";
    type Record = AuthorsRecord;
}

impl Collection for AuthorsRecord {
    const NSID: &'static str = "sh.weaver.notebook.authors";
    type Record = AuthorsRecord;
}

impl<'a> LexiconSchema for Authors<'a> {
    fn nsid() -> &'static str {
        "sh.weaver.notebook.authors"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_weaver_notebook_authors()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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

/// Builder for constructing an instance of this type
pub struct AuthorListItemBuilder<'a, S: author_list_item_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<i64>, Option<AuthorListItemProfile<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> AuthorListItem<'a> {
    /// Create a new builder for this type
    pub fn new() -> AuthorListItemBuilder<'a, author_list_item_state::Empty> {
        AuthorListItemBuilder::new()
    }
}

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

impl<'a, S: author_list_item_state::State> AuthorListItemBuilder<'a, S> {
    /// Set the `index` field (optional)
    pub fn index(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `index` field to an Option value (optional)
    pub fn maybe_index(mut self, value: Option<i64>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<'a, S: author_list_item_state::State> AuthorListItemBuilder<'a, S> {
    /// Set the `profile` field (optional)
    pub fn profile(
        mut self,
        value: impl Into<Option<AuthorListItemProfile<'a>>>,
    ) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `profile` field to an Option value (optional)
    pub fn maybe_profile(mut self, value: Option<AuthorListItemProfile<'a>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<'a, S> AuthorListItemBuilder<'a, S>
where
    S: author_list_item_state::State,
    S::ProfileIndex: author_list_item_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> AuthorListItem<'a> {
        AuthorListItem {
            index: self._fields.0,
            profile: self._fields.1,
            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>,
        >,
    ) -> AuthorListItem<'a> {
        AuthorListItem {
            index: self._fields.0,
            profile: self._fields.1,
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_sh_weaver_notebook_authors() -> 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("sh.weaver.notebook.authors"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("authorListItem"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("A single author in a Weaver notebook."),
                    ),
                    required: Some(vec![SmolStr::new_static("profile, index")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("index"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("profile"),
                            LexObjectProperty::Union(LexRefUnion {
                                refs: vec![
                                    CowStr::new_static("app.bsky.actor.defs#profileViewBasic"),
                                    CowStr::new_static("sh.weaver.actor.defs#profileView")
                                ],
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static("Authors of a Weaver notebook."),
                    ),
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(vec![SmolStr::new_static("authorList")]),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("authorList"),
                                LexObjectProperty::Array(LexArray {
                                    items: LexArrayItem::Ref(LexRef {
                                        r#ref: CowStr::new_static("#authorListItem"),
                                        ..Default::default()
                                    }),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

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

/// Builder for constructing an instance of this type
pub struct AuthorsBuilder<'a, S: authors_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<Vec<authors::AuthorListItem<'a>>>, Option<Datetime>),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> Authors<'a> {
    /// Create a new builder for this type
    pub fn new() -> AuthorsBuilder<'a, authors_state::Empty> {
        AuthorsBuilder::new()
    }
}

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

impl<'a, S> AuthorsBuilder<'a, S>
where
    S: authors_state::State,
    S::AuthorList: authors_state::IsUnset,
{
    /// Set the `authorList` field (required)
    pub fn author_list(
        mut self,
        value: impl Into<Vec<authors::AuthorListItem<'a>>>,
    ) -> AuthorsBuilder<'a, authors_state::SetAuthorList<S>> {
        self._fields.0 = Option::Some(value.into());
        AuthorsBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

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

impl<'a, S> AuthorsBuilder<'a, S>
where
    S: authors_state::State,
    S::AuthorList: authors_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Authors<'a> {
        Authors {
            author_list: self._fields.0.unwrap(),
            created_at: self._fields.1,
            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>,
        >,
    ) -> Authors<'a> {
        Authors {
            author_list: self._fields.0.unwrap(),
            created_at: self._fields.1,
            extra_data: Some(extra_data),
        }
    }
}