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

pub mod gate;
pub mod message;
pub mod profile;


#[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::{AtUri, Cid, Datetime};
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, lexicon};
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::place_stream::chat::profile::Profile;
use crate::place_stream::chat;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct MessageView<'a> {
    #[serde(borrow)]
    pub author: ProfileViewBasic<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub chat_profile: Option<Profile<'a>>,
    #[serde(borrow)]
    pub cid: Cid<'a>,
    ///If true, this message has been deleted or labeled and should be cleared from the cache
    #[serde(skip_serializing_if = "Option::is_none")]
    pub deleted: Option<bool>,
    pub indexed_at: Datetime,
    #[serde(borrow)]
    pub record: Data<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub reply_to: Option<MessageViewReplyTo<'a>>,
    #[serde(borrow)]
    pub uri: AtUri<'a>,
}


#[jacquard_derive::open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum MessageViewReplyTo<'a> {
    #[serde(rename = "place.stream.chat.defs#messageView")]
    MessageView(Box<chat::MessageView<'a>>),
}

impl<'a> LexiconSchema for MessageView<'a> {
    fn nsid() -> &'static str {
        "place.stream.chat.defs"
    }
    fn def_name() -> &'static str {
        "messageView"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_place_stream_chat_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

pub mod message_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 Cid;
        type Uri;
        type Record;
        type IndexedAt;
        type Author;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Cid = Unset;
        type Uri = Unset;
        type Record = Unset;
        type IndexedAt = Unset;
        type Author = Unset;
    }
    ///State transition - sets the `cid` field to Set
    pub struct SetCid<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCid<S> {}
    impl<S: State> State for SetCid<S> {
        type Cid = Set<members::cid>;
        type Uri = S::Uri;
        type Record = S::Record;
        type IndexedAt = S::IndexedAt;
        type Author = S::Author;
    }
    ///State transition - sets the `uri` field to Set
    pub struct SetUri<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetUri<S> {}
    impl<S: State> State for SetUri<S> {
        type Cid = S::Cid;
        type Uri = Set<members::uri>;
        type Record = S::Record;
        type IndexedAt = S::IndexedAt;
        type Author = S::Author;
    }
    ///State transition - sets the `record` field to Set
    pub struct SetRecord<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetRecord<S> {}
    impl<S: State> State for SetRecord<S> {
        type Cid = S::Cid;
        type Uri = S::Uri;
        type Record = Set<members::record>;
        type IndexedAt = S::IndexedAt;
        type Author = S::Author;
    }
    ///State transition - sets the `indexed_at` field to Set
    pub struct SetIndexedAt<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetIndexedAt<S> {}
    impl<S: State> State for SetIndexedAt<S> {
        type Cid = S::Cid;
        type Uri = S::Uri;
        type Record = S::Record;
        type IndexedAt = Set<members::indexed_at>;
        type Author = S::Author;
    }
    ///State transition - sets the `author` field to Set
    pub struct SetAuthor<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetAuthor<S> {}
    impl<S: State> State for SetAuthor<S> {
        type Cid = S::Cid;
        type Uri = S::Uri;
        type Record = S::Record;
        type IndexedAt = S::IndexedAt;
        type Author = Set<members::author>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `cid` field
        pub struct cid(());
        ///Marker type for the `uri` field
        pub struct uri(());
        ///Marker type for the `record` field
        pub struct record(());
        ///Marker type for the `indexed_at` field
        pub struct indexed_at(());
        ///Marker type for the `author` field
        pub struct author(());
    }
}

/// Builder for constructing an instance of this type
pub struct MessageViewBuilder<'a, S: message_view_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<ProfileViewBasic<'a>>,
        Option<Profile<'a>>,
        Option<Cid<'a>>,
        Option<bool>,
        Option<Datetime>,
        Option<Data<'a>>,
        Option<MessageViewReplyTo<'a>>,
        Option<AtUri<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> MessageView<'a> {
    /// Create a new builder for this type
    pub fn new() -> MessageViewBuilder<'a, message_view_state::Empty> {
        MessageViewBuilder::new()
    }
}

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

impl<'a, S> MessageViewBuilder<'a, S>
where
    S: message_view_state::State,
    S::Author: message_view_state::IsUnset,
{
    /// Set the `author` field (required)
    pub fn author(
        mut self,
        value: impl Into<ProfileViewBasic<'a>>,
    ) -> MessageViewBuilder<'a, message_view_state::SetAuthor<S>> {
        self._fields.0 = Option::Some(value.into());
        MessageViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: message_view_state::State> MessageViewBuilder<'a, S> {
    /// Set the `chatProfile` field (optional)
    pub fn chat_profile(mut self, value: impl Into<Option<Profile<'a>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `chatProfile` field to an Option value (optional)
    pub fn maybe_chat_profile(mut self, value: Option<Profile<'a>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<'a, S> MessageViewBuilder<'a, S>
where
    S: message_view_state::State,
    S::Cid: message_view_state::IsUnset,
{
    /// Set the `cid` field (required)
    pub fn cid(
        mut self,
        value: impl Into<Cid<'a>>,
    ) -> MessageViewBuilder<'a, message_view_state::SetCid<S>> {
        self._fields.2 = Option::Some(value.into());
        MessageViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: message_view_state::State> MessageViewBuilder<'a, S> {
    /// Set the `deleted` field (optional)
    pub fn deleted(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `deleted` field to an Option value (optional)
    pub fn maybe_deleted(mut self, value: Option<bool>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<'a, S> MessageViewBuilder<'a, S>
where
    S: message_view_state::State,
    S::IndexedAt: message_view_state::IsUnset,
{
    /// Set the `indexedAt` field (required)
    pub fn indexed_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> MessageViewBuilder<'a, message_view_state::SetIndexedAt<S>> {
        self._fields.4 = Option::Some(value.into());
        MessageViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> MessageViewBuilder<'a, S>
where
    S: message_view_state::State,
    S::Record: message_view_state::IsUnset,
{
    /// Set the `record` field (required)
    pub fn record(
        mut self,
        value: impl Into<Data<'a>>,
    ) -> MessageViewBuilder<'a, message_view_state::SetRecord<S>> {
        self._fields.5 = Option::Some(value.into());
        MessageViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: message_view_state::State> MessageViewBuilder<'a, S> {
    /// Set the `replyTo` field (optional)
    pub fn reply_to(mut self, value: impl Into<Option<MessageViewReplyTo<'a>>>) -> Self {
        self._fields.6 = value.into();
        self
    }
    /// Set the `replyTo` field to an Option value (optional)
    pub fn maybe_reply_to(mut self, value: Option<MessageViewReplyTo<'a>>) -> Self {
        self._fields.6 = value;
        self
    }
}

impl<'a, S> MessageViewBuilder<'a, S>
where
    S: message_view_state::State,
    S::Uri: message_view_state::IsUnset,
{
    /// Set the `uri` field (required)
    pub fn uri(
        mut self,
        value: impl Into<AtUri<'a>>,
    ) -> MessageViewBuilder<'a, message_view_state::SetUri<S>> {
        self._fields.7 = Option::Some(value.into());
        MessageViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> MessageViewBuilder<'a, S>
where
    S: message_view_state::State,
    S::Cid: message_view_state::IsSet,
    S::Uri: message_view_state::IsSet,
    S::Record: message_view_state::IsSet,
    S::IndexedAt: message_view_state::IsSet,
    S::Author: message_view_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> MessageView<'a> {
        MessageView {
            author: self._fields.0.unwrap(),
            chat_profile: self._fields.1,
            cid: self._fields.2.unwrap(),
            deleted: self._fields.3,
            indexed_at: self._fields.4.unwrap(),
            record: self._fields.5.unwrap(),
            reply_to: self._fields.6,
            uri: self._fields.7.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, Data<'a>>,
    ) -> MessageView<'a> {
        MessageView {
            author: self._fields.0.unwrap(),
            chat_profile: self._fields.1,
            cid: self._fields.2.unwrap(),
            deleted: self._fields.3,
            indexed_at: self._fields.4.unwrap(),
            record: self._fields.5.unwrap(),
            reply_to: self._fields.6,
            uri: self._fields.7.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_place_stream_chat_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("place.stream.chat.defs"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("messageView"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("uri"), SmolStr::new_static("cid"),
                            SmolStr::new_static("author"), SmolStr::new_static("record"),
                            SmolStr::new_static("indexedAt")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("author"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static(
                                    "app.bsky.actor.defs#profileViewBasic",
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("chatProfile"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("place.stream.chat.profile"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("cid"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Cid),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("deleted"),
                            LexObjectProperty::Boolean(LexBoolean {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("indexedAt"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("record"),
                            LexObjectProperty::Unknown(LexUnknown {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("replyTo"),
                            LexObjectProperty::Union(LexRefUnion {
                                refs: vec![CowStr::new_static("#messageView")],
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("uri"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}