// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: network.slices.slice.getSyncSummary
//
// 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::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::network_slices::slice::get_sync_summary;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct CollectionSummary<S: BosStr = DefaultStr> {
    pub collection: S,
    pub estimated_repos: i64,
    pub is_external: bool,
    #[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 GetSyncSummary<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub collections: Option<Vec<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub external_collections: Option<Vec<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub repos: Option<Vec<S>>,
    pub slice: S,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GetSyncSummaryOutput<S: BosStr = DefaultStr> {
    ///The actual limit applied (user-specified or default)
    pub applied_limit: i64,
    ///Number of repositories after applying limit
    pub capped_repos: i64,
    pub collections_summary: Vec<get_sync_summary::CollectionSummary<S>>,
    ///Total number of repositories that would be synced
    pub total_repos: i64,
    ///Whether the sync would be limited by maxRepos
    pub would_be_capped: bool,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> LexiconSchema for CollectionSummary<S> {
    fn nsid() -> &'static str {
        "network.slices.slice.getSyncSummary"
    }
    fn def_name() -> &'static str {
        "collectionSummary"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_network_slices_slice_getSyncSummary()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

/** Response marker for the `network.slices.slice.getSyncSummary` query.

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `GetSyncSummaryOutput<S>` for this endpoint.*/
pub struct GetSyncSummaryResponse;
impl jacquard_common::xrpc::XrpcResp for GetSyncSummaryResponse {
    const NSID: &'static str = "network.slices.slice.getSyncSummary";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = GetSyncSummaryOutput<S>;
    type Err = jacquard_common::xrpc::GenericError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for GetSyncSummary<S> {
    const NSID: &'static str = "network.slices.slice.getSyncSummary";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = GetSyncSummaryResponse;
}

/** Endpoint marker for the `network.slices.slice.getSyncSummary` query.

Path: `/xrpc/network.slices.slice.getSyncSummary`. The request payload type is `GetSyncSummary<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
pub struct GetSyncSummaryRequest;
impl jacquard_common::xrpc::XrpcEndpoint for GetSyncSummaryRequest {
    const PATH: &'static str = "/xrpc/network.slices.slice.getSyncSummary";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<S: BosStr> = GetSyncSummary<S>;
    type Response = GetSyncSummaryResponse;
}

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

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

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

impl<S: BosStr> CollectionSummary<S> {
    /// Create a new builder for this type
    pub fn builder() -> CollectionSummaryBuilder<collection_summary_state::Empty, S> {
        CollectionSummaryBuilder::builder()
    }
}

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

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

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

impl<St, S: BosStr> CollectionSummaryBuilder<St, S>
where
    St: collection_summary_state::State,
    St::EstimatedRepos: collection_summary_state::IsUnset,
{
    /// Set the `estimatedRepos` field (required)
    pub fn estimated_repos(
        mut self,
        value: impl Into<i64>,
    ) -> CollectionSummaryBuilder<collection_summary_state::SetEstimatedRepos<St>, S> {
        self._fields.1 = Option::Some(value.into());
        CollectionSummaryBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> CollectionSummaryBuilder<St, S>
where
    St: collection_summary_state::State,
    St::IsExternal: collection_summary_state::IsUnset,
{
    /// Set the `isExternal` field (required)
    pub fn is_external(
        mut self,
        value: impl Into<bool>,
    ) -> CollectionSummaryBuilder<collection_summary_state::SetIsExternal<St>, S> {
        self._fields.2 = Option::Some(value.into());
        CollectionSummaryBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> CollectionSummaryBuilder<St, S>
where
    St: collection_summary_state::State,
    St::Collection: collection_summary_state::IsSet,
    St::EstimatedRepos: collection_summary_state::IsSet,
    St::IsExternal: collection_summary_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> CollectionSummary<S> {
        CollectionSummary {
            collection: self._fields.0.unwrap(),
            estimated_repos: self._fields.1.unwrap(),
            is_external: 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<SmolStr, Data<S>>,
    ) -> CollectionSummary<S> {
        CollectionSummary {
            collection: self._fields.0.unwrap(),
            estimated_repos: self._fields.1.unwrap(),
            is_external: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_network_slices_slice_getSyncSummary() -> 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("network.slices.slice.getSyncSummary"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("collectionSummary"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("collection"),
                            SmolStr::new_static("estimatedRepos"),
                            SmolStr::new_static("isExternal")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("collection"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("estimatedRepos"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("isExternal"),
                            LexObjectProperty::Boolean(LexBoolean {
                                ..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("slice")]),
                            properties: {
                                #[allow(unused_mut)]
                                let mut map = BTreeMap::new();
                                map.insert(
                                    SmolStr::new_static("collections"),
                                    LexXrpcParametersProperty::Array(LexPrimitiveArray {
                                        items: LexPrimitiveArrayItem::String(LexString {
                                            ..Default::default()
                                        }),
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("externalCollections"),
                                    LexXrpcParametersProperty::Array(LexPrimitiveArray {
                                        items: LexPrimitiveArrayItem::String(LexString {
                                            ..Default::default()
                                        }),
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("repos"),
                                    LexXrpcParametersProperty::Array(LexPrimitiveArray {
                                        items: LexPrimitiveArrayItem::String(LexString {
                                            ..Default::default()
                                        }),
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("slice"),
                                    LexXrpcParametersProperty::String(LexString {
                                        description: Some(
                                            CowStr::new_static("URI of the slice to sync"),
                                        ),
                                        ..Default::default()
                                    }),
                                );
                                map
                            },
                            ..Default::default()
                        }),
                    ),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

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

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

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

impl<S: BosStr> GetSyncSummary<S> {
    /// Create a new builder for this type
    pub fn builder() -> GetSyncSummaryBuilder<get_sync_summary_state::Empty, S> {
        GetSyncSummaryBuilder::builder()
    }
}

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

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

impl<St: get_sync_summary_state::State, S: BosStr> GetSyncSummaryBuilder<St, S> {
    /// Set the `collections` field (optional)
    pub fn collections(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `collections` field to an Option value (optional)
    pub fn maybe_collections(mut self, value: Option<Vec<S>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St: get_sync_summary_state::State, S: BosStr> GetSyncSummaryBuilder<St, S> {
    /// Set the `externalCollections` field (optional)
    pub fn external_collections(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `externalCollections` field to an Option value (optional)
    pub fn maybe_external_collections(mut self, value: Option<Vec<S>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St: get_sync_summary_state::State, S: BosStr> GetSyncSummaryBuilder<St, S> {
    /// Set the `repos` field (optional)
    pub fn repos(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `repos` field to an Option value (optional)
    pub fn maybe_repos(mut self, value: Option<Vec<S>>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<St, S: BosStr> GetSyncSummaryBuilder<St, S>
where
    St: get_sync_summary_state::State,
    St::Slice: get_sync_summary_state::IsUnset,
{
    /// Set the `slice` field (required)
    pub fn slice(
        mut self,
        value: impl Into<S>,
    ) -> GetSyncSummaryBuilder<get_sync_summary_state::SetSlice<St>, S> {
        self._fields.3 = Option::Some(value.into());
        GetSyncSummaryBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> GetSyncSummaryBuilder<St, S>
where
    St: get_sync_summary_state::State,
    St::Slice: get_sync_summary_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> GetSyncSummary<S> {
        GetSyncSummary {
            collections: self._fields.0,
            external_collections: self._fields.1,
            repos: self._fields.2,
            slice: self._fields.3.unwrap(),
        }
    }
}