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

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::ident::AtIdentifier;
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::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.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ListWithMembership<'a> {
    #[serde(borrow)]
    pub list: ListView<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub list_item: Option<ListItemView<'a>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetListsWithMembership<'a> {
    #[serde(borrow)]
    pub actor: AtIdentifier<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cursor: Option<CowStr<'a>>,
    ///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")]
    #[serde(borrow)]
    pub purposes: Option<Vec<CowStr<'a>>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetListsWithMembershipOutput<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cursor: Option<CowStr<'a>>,
    #[serde(borrow)]
    pub lists_with_membership: Vec<get_lists_with_membership::ListWithMembership<'a>>,
}

impl<'a> LexiconSchema for ListWithMembership<'a> {
    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 type for app.bsky.graph.getListsWithMembership
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<'de> = GetListsWithMembershipOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

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

/// Endpoint type for app.bsky.graph.getListsWithMembership
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<'de> = GetListsWithMembership<'de>;
    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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetList<S> {}
    impl<S: State> State for SetList<S> {
        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<'a, S: list_with_membership_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<ListView<'a>>, Option<ListItemView<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

impl<'a, S: list_with_membership_state::State> ListWithMembershipBuilder<'a, S> {
    /// Set the `listItem` field (optional)
    pub fn list_item(mut self, value: impl Into<Option<ListItemView<'a>>>) -> 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<'a>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<'a, S> ListWithMembershipBuilder<'a, S>
where
    S: list_with_membership_state::State,
    S::List: list_with_membership_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> ListWithMembership<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> ListWithMembership<'a> {
        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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetActor<S> {}
    impl<S: State> State for SetActor<S> {
        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<'a, S: get_lists_with_membership_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<AtIdentifier<'a>>,
        Option<CowStr<'a>>,
        Option<i64>,
        Option<Vec<CowStr<'a>>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

impl<
    'a,
    S: get_lists_with_membership_state::State,
> GetListsWithMembershipBuilder<'a, 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<
    'a,
    S: get_lists_with_membership_state::State,
> GetListsWithMembershipBuilder<'a, S> {
    /// Set the `purposes` field (optional)
    pub fn purposes(mut self, value: impl Into<Option<Vec<CowStr<'a>>>>) -> 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<CowStr<'a>>>) -> Self {
        self._fields.3 = value;
        self
    }
}

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