// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: com.atproto.sync.listReposByCollection
//
// 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::string::{Did, Nsid};
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::com_atproto::sync::list_repos_by_collection;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ListReposByCollection<S: BosStr = DefaultStr> {
    pub collection: Nsid<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cursor: Option<S>,
    /// Defaults to `500`. Min: 1. Max: 2000.
    #[serde(default = "_default_limit")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ListReposByCollectionOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cursor: Option<S>,
    pub repos: Vec<list_repos_by_collection::Repo<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 Repo<S: BosStr = DefaultStr> {
    pub did: Did<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/** Response marker for the `com.atproto.sync.listReposByCollection` query.

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `ListReposByCollectionOutput<S>` for this endpoint.*/
pub struct ListReposByCollectionResponse;
impl jacquard_common::xrpc::XrpcResp for ListReposByCollectionResponse {
    const NSID: &'static str = "com.atproto.sync.listReposByCollection";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = ListReposByCollectionOutput<S>;
    type Err = jacquard_common::xrpc::GenericError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for ListReposByCollection<S> {
    const NSID: &'static str = "com.atproto.sync.listReposByCollection";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = ListReposByCollectionResponse;
}

/** Endpoint marker for the `com.atproto.sync.listReposByCollection` query.

Path: `/xrpc/com.atproto.sync.listReposByCollection`. The request payload type is `ListReposByCollection<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
pub struct ListReposByCollectionRequest;
impl jacquard_common::xrpc::XrpcEndpoint for ListReposByCollectionRequest {
    const PATH: &'static str = "/xrpc/com.atproto.sync.listReposByCollection";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<S: BosStr> = ListReposByCollection<S>;
    type Response = ListReposByCollectionResponse;
}

impl<S: BosStr> LexiconSchema for Repo<S> {
    fn nsid() -> &'static str {
        "com.atproto.sync.listReposByCollection"
    }
    fn def_name() -> &'static str {
        "repo"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_atproto_sync_listReposByCollection()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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

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

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

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

impl<S: BosStr> ListReposByCollection<S> {
    /// Create a new builder for this type
    pub fn builder() -> ListReposByCollectionBuilder<
        list_repos_by_collection_state::Empty,
        S,
    > {
        ListReposByCollectionBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> ListReposByCollectionBuilder<St, S>
where
    St: list_repos_by_collection_state::State,
    St::Collection: list_repos_by_collection_state::IsUnset,
{
    /// Set the `collection` field (required)
    pub fn collection(
        mut self,
        value: impl Into<Nsid<S>>,
    ) -> ListReposByCollectionBuilder<
        list_repos_by_collection_state::SetCollection<St>,
        S,
    > {
        self._fields.0 = Option::Some(value.into());
        ListReposByCollectionBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<
    St: list_repos_by_collection_state::State,
    S: BosStr,
> ListReposByCollectionBuilder<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: list_repos_by_collection_state::State,
    S: BosStr,
> ListReposByCollectionBuilder<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, S: BosStr> ListReposByCollectionBuilder<St, S>
where
    St: list_repos_by_collection_state::State,
    St::Collection: list_repos_by_collection_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ListReposByCollection<S> {
        ListReposByCollection {
            collection: self._fields.0.unwrap(),
            cursor: self._fields.1,
            limit: self._fields.2,
        }
    }
}

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

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

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

impl<S: BosStr> Repo<S> {
    /// Create a new builder for this type
    pub fn builder() -> RepoBuilder<repo_state::Empty, S> {
        RepoBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> RepoBuilder<St, S>
where
    St: repo_state::State,
    St::Did: repo_state::IsUnset,
{
    /// Set the `did` field (required)
    pub fn did(
        mut self,
        value: impl Into<Did<S>>,
    ) -> RepoBuilder<repo_state::SetDid<St>, S> {
        self._fields.0 = Option::Some(value.into());
        RepoBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> RepoBuilder<St, S>
where
    St: repo_state::State,
    St::Did: repo_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Repo<S> {
        Repo {
            did: self._fields.0.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Repo<S> {
        Repo {
            did: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_com_atproto_sync_listReposByCollection() -> 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("com.atproto.sync.listReposByCollection"),
        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("collection")]),
                            properties: {
                                #[allow(unused_mut)]
                                let mut map = BTreeMap::new();
                                map.insert(
                                    SmolStr::new_static("collection"),
                                    LexXrpcParametersProperty::String(LexString {
                                        format: Some(LexStringFormat::Nsid),
                                        ..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
                            },
                            ..Default::default()
                        }),
                    ),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("repo"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("did")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("did"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}