// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: app.bsky.unspecced.getPostThreadOtherV2
//
// 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;

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::string::AtUri;
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::unspecced::ThreadItemPost;
use crate::app_bsky::unspecced::get_post_thread_other_v2;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetPostThreadOtherV2<'a> {
    #[serde(borrow)]
    pub anchor: AtUri<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetPostThreadOtherV2Output<'a> {
    ///A flat list of other thread items. The depth of each item is indicated by the depth property inside the item.
    #[serde(borrow)]
    pub thread: Vec<get_post_thread_other_v2::ThreadItem<'a>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ThreadItem<'a> {
    ///The nesting level of this item in the thread. Depth 0 means the anchor item. Items above have negative depths, items below have positive depths.
    pub depth: i64,
    #[serde(borrow)]
    pub uri: AtUri<'a>,
    #[serde(borrow)]
    pub value: ThreadItemPost<'a>,
}

/// Response type for app.bsky.unspecced.getPostThreadOtherV2
pub struct GetPostThreadOtherV2Response;
impl jacquard_common::xrpc::XrpcResp for GetPostThreadOtherV2Response {
    const NSID: &'static str = "app.bsky.unspecced.getPostThreadOtherV2";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = GetPostThreadOtherV2Output<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for GetPostThreadOtherV2<'a> {
    const NSID: &'static str = "app.bsky.unspecced.getPostThreadOtherV2";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = GetPostThreadOtherV2Response;
}

/// Endpoint type for app.bsky.unspecced.getPostThreadOtherV2
pub struct GetPostThreadOtherV2Request;
impl jacquard_common::xrpc::XrpcEndpoint for GetPostThreadOtherV2Request {
    const PATH: &'static str = "/xrpc/app.bsky.unspecced.getPostThreadOtherV2";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<'de> = GetPostThreadOtherV2<'de>;
    type Response = GetPostThreadOtherV2Response;
}

impl<'a> LexiconSchema for ThreadItem<'a> {
    fn nsid() -> &'static str {
        "app.bsky.unspecced.getPostThreadOtherV2"
    }
    fn def_name() -> &'static str {
        "threadItem"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_bsky_unspecced_getPostThreadOtherV2()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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

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

impl<'a> GetPostThreadOtherV2<'a> {
    /// Create a new builder for this type
    pub fn new() -> GetPostThreadOtherV2Builder<
        'a,
        get_post_thread_other_v2_state::Empty,
    > {
        GetPostThreadOtherV2Builder::new()
    }
}

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

impl<'a, S> GetPostThreadOtherV2Builder<'a, S>
where
    S: get_post_thread_other_v2_state::State,
    S::Anchor: get_post_thread_other_v2_state::IsUnset,
{
    /// Set the `anchor` field (required)
    pub fn anchor(
        mut self,
        value: impl Into<AtUri<'a>>,
    ) -> GetPostThreadOtherV2Builder<'a, get_post_thread_other_v2_state::SetAnchor<S>> {
        self._fields.0 = Option::Some(value.into());
        GetPostThreadOtherV2Builder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> GetPostThreadOtherV2Builder<'a, S>
where
    S: get_post_thread_other_v2_state::State,
    S::Anchor: get_post_thread_other_v2_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> GetPostThreadOtherV2<'a> {
        GetPostThreadOtherV2 {
            anchor: self._fields.0.unwrap(),
        }
    }
}

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

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

impl<'a> ThreadItem<'a> {
    /// Create a new builder for this type
    pub fn new() -> ThreadItemBuilder<'a, thread_item_state::Empty> {
        ThreadItemBuilder::new()
    }
}

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

impl<'a, S> ThreadItemBuilder<'a, S>
where
    S: thread_item_state::State,
    S::Depth: thread_item_state::IsUnset,
{
    /// Set the `depth` field (required)
    pub fn depth(
        mut self,
        value: impl Into<i64>,
    ) -> ThreadItemBuilder<'a, thread_item_state::SetDepth<S>> {
        self._fields.0 = Option::Some(value.into());
        ThreadItemBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

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

impl<'a, S> ThreadItemBuilder<'a, S>
where
    S: thread_item_state::State,
    S::Value: thread_item_state::IsUnset,
{
    /// Set the `value` field (required)
    pub fn value(
        mut self,
        value: impl Into<ThreadItemPost<'a>>,
    ) -> ThreadItemBuilder<'a, thread_item_state::SetValue<S>> {
        self._fields.2 = Option::Some(value.into());
        ThreadItemBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> ThreadItemBuilder<'a, S>
where
    S: thread_item_state::State,
    S::Value: thread_item_state::IsSet,
    S::Depth: thread_item_state::IsSet,
    S::Uri: thread_item_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> ThreadItem<'a> {
        ThreadItem {
            depth: self._fields.0.unwrap(),
            uri: self._fields.1.unwrap(),
            value: 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>,
        >,
    ) -> ThreadItem<'a> {
        ThreadItem {
            depth: self._fields.0.unwrap(),
            uri: self._fields.1.unwrap(),
            value: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_app_bsky_unspecced_getPostThreadOtherV2() -> 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.unspecced.getPostThreadOtherV2"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcQuery(LexXrpcQuery {
                    parameters: Some(
                        LexXrpcQueryParameter::Params(LexXrpcParameters {
                            required: Some(vec![SmolStr::new_static("anchor")]),
                            properties: {
                                #[allow(unused_mut)]
                                let mut map = BTreeMap::new();
                                map.insert(
                                    SmolStr::new_static("anchor"),
                                    LexXrpcParametersProperty::String(LexString {
                                        description: Some(
                                            CowStr::new_static(
                                                "Reference (AT-URI) to post record. This is the anchor post.",
                                            ),
                                        ),
                                        format: Some(LexStringFormat::AtUri),
                                        ..Default::default()
                                    }),
                                );
                                map
                            },
                            ..Default::default()
                        }),
                    ),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("threadItem"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("uri"), SmolStr::new_static("depth"),
                            SmolStr::new_static("value")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("depth"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("uri"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("value"),
                            LexObjectProperty::Union(LexRefUnion {
                                refs: vec![
                                    CowStr::new_static("app.bsky.unspecced.defs#threadItemPost")
                                ],
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}