// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: app.bsky.graph.getListsWithMembership
//
// 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, 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::ident::AtIdentifier;
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
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::graph::ListItemView;
use crate::app_bsky::graph::ListView;
use crate::app_bsky::graph::get_lists_with_membership;
/// A list and an optional list item indicating membership of a target user to that list.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ListWithMembership<S: BosStr = DefaultStr> {
    pub list: ListView<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub list_item: Option<ListItemView<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 GetListsWithMembership<S: BosStr = DefaultStr> {
    pub actor: AtIdentifier<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cursor: Option<S>,
    /// Defaults to `50`. Min: 1. Max: 100.
    #[serde(default = "_default_limit")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub purposes: Option<Vec<S>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GetListsWithMembershipOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cursor: Option<S>,
    pub lists_with_membership: Vec<get_lists_with_membership::ListWithMembership<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> LexiconSchema for ListWithMembership<S> {
    fn nsid() -> &'static str {
        "app.bsky.graph.getListsWithMembership"
    }
    fn def_name() -> &'static str {
        "listWithMembership"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_bsky_graph_getListsWithMembership()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

/** Response marker for the `app.bsky.graph.getListsWithMembership` query.

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `GetListsWithMembershipOutput<S>` for this endpoint.*/
pub struct GetListsWithMembershipResponse;
impl jacquard_common::xrpc::XrpcResp for GetListsWithMembershipResponse {
    const NSID: &'static str = "app.bsky.graph.getListsWithMembership";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = GetListsWithMembershipOutput<S>;
    type Err = jacquard_common::xrpc::GenericError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for GetListsWithMembership<S> {
    const NSID: &'static str = "app.bsky.graph.getListsWithMembership";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = GetListsWithMembershipResponse;
}

/** Endpoint marker for the `app.bsky.graph.getListsWithMembership` query.

Path: `/xrpc/app.bsky.graph.getListsWithMembership`. The request payload type is `GetListsWithMembership<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
pub struct GetListsWithMembershipRequest;
impl jacquard_common::xrpc::XrpcEndpoint for GetListsWithMembershipRequest {
    const PATH: &'static str = "/xrpc/app.bsky.graph.getListsWithMembership";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<S: BosStr> = GetListsWithMembership<S>;
    type Response = GetListsWithMembershipResponse;
}

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

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

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

impl<S: BosStr> ListWithMembership<S> {
    /// Create a new builder for this type
    pub fn builder() -> ListWithMembershipBuilder<list_with_membership_state::Empty, S> {
        ListWithMembershipBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> ListWithMembershipBuilder<St, S>
where
    St: list_with_membership_state::State,
    St::List: list_with_membership_state::IsUnset,
{
    /// Set the `list` field (required)
    pub fn list(
        mut self,
        value: impl Into<ListView<S>>,
    ) -> ListWithMembershipBuilder<list_with_membership_state::SetList<St>, S> {
        self._fields.0 = Option::Some(value.into());
        ListWithMembershipBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: list_with_membership_state::State, S: BosStr> ListWithMembershipBuilder<St, S> {
    /// Set the `listItem` field (optional)
    pub fn list_item(mut self, value: impl Into<Option<ListItemView<S>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `listItem` field to an Option value (optional)
    pub fn maybe_list_item(mut self, value: Option<ListItemView<S>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St, S: BosStr> ListWithMembershipBuilder<St, S>
where
    St: list_with_membership_state::State,
    St::List: list_with_membership_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ListWithMembership<S> {
        ListWithMembership {
            list: self._fields.0.unwrap(),
            list_item: self._fields.1,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> ListWithMembership<S> {
        ListWithMembership {
            list: self._fields.0.unwrap(),
            list_item: self._fields.1,
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_app_bsky_graph_getListsWithMembership() -> 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.graph.getListsWithMembership"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("listWithMembership"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "A list and an optional list item indicating membership of a target user to that list.",
                        ),
                    ),
                    required: Some(vec![SmolStr::new_static("list")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("list"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("app.bsky.graph.defs#listView"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("listItem"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static(
                                    "app.bsky.graph.defs#listItemView",
                                ),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcQuery(LexXrpcQuery {
                    parameters: Some(
                        LexXrpcQueryParameter::Params(LexXrpcParameters {
                            required: Some(vec![SmolStr::new_static("actor")]),
                            properties: {
                                #[allow(unused_mut)]
                                let mut map = BTreeMap::new();
                                map.insert(
                                    SmolStr::new_static("actor"),
                                    LexXrpcParametersProperty::String(LexString {
                                        description: Some(
                                            CowStr::new_static(
                                                "The account (actor) to check for membership.",
                                            ),
                                        ),
                                        format: Some(LexStringFormat::AtIdentifier),
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("cursor"),
                                    LexXrpcParametersProperty::String(LexString {
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("limit"),
                                    LexXrpcParametersProperty::Integer(LexInteger {
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("purposes"),
                                    LexXrpcParametersProperty::Array(LexPrimitiveArray {
                                        items: LexPrimitiveArrayItem::String(LexString {
                                            ..Default::default()
                                        }),
                                        ..Default::default()
                                    }),
                                );
                                map
                            },
                            ..Default::default()
                        }),
                    ),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

fn _default_limit() -> Option<i64> {
    Some(50i64)
}

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

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

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

impl<S: BosStr> GetListsWithMembership<S> {
    /// Create a new builder for this type
    pub fn builder() -> GetListsWithMembershipBuilder<
        get_lists_with_membership_state::Empty,
        S,
    > {
        GetListsWithMembershipBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> GetListsWithMembershipBuilder<St, S>
where
    St: get_lists_with_membership_state::State,
    St::Actor: get_lists_with_membership_state::IsUnset,
{
    /// Set the `actor` field (required)
    pub fn actor(
        mut self,
        value: impl Into<AtIdentifier<S>>,
    ) -> GetListsWithMembershipBuilder<
        get_lists_with_membership_state::SetActor<St>,
        S,
    > {
        self._fields.0 = Option::Some(value.into());
        GetListsWithMembershipBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<
    St: get_lists_with_membership_state::State,
    S: BosStr,
> GetListsWithMembershipBuilder<St, S> {
    /// Set the `cursor` field (optional)
    pub fn cursor(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `cursor` field to an Option value (optional)
    pub fn maybe_cursor(mut self, value: Option<S>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<
    St: get_lists_with_membership_state::State,
    S: BosStr,
> GetListsWithMembershipBuilder<St, S> {
    /// Set the `limit` field (optional)
    pub fn limit(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `limit` field to an Option value (optional)
    pub fn maybe_limit(mut self, value: Option<i64>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<
    St: get_lists_with_membership_state::State,
    S: BosStr,
> GetListsWithMembershipBuilder<St, S> {
    /// Set the `purposes` field (optional)
    pub fn purposes(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `purposes` field to an Option value (optional)
    pub fn maybe_purposes(mut self, value: Option<Vec<S>>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<St, S: BosStr> GetListsWithMembershipBuilder<St, S>
where
    St: get_lists_with_membership_state::State,
    St::Actor: get_lists_with_membership_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> GetListsWithMembership<S> {
        GetListsWithMembership {
            actor: self._fields.0.unwrap(),
            cursor: self._fields.1,
            limit: self._fields.2,
            purposes: self._fields.3,
        }
    }
}