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

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
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::network_slices::slice::get_sync_summary;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct CollectionSummary<'a> {
    #[serde(borrow)]
    pub collection: CowStr<'a>,
    pub estimated_repos: i64,
    pub is_external: bool,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetSyncSummary<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub collections: Option<Vec<CowStr<'a>>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub external_collections: Option<Vec<CowStr<'a>>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub repos: Option<Vec<CowStr<'a>>>,
    #[serde(borrow)]
    pub slice: CowStr<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetSyncSummaryOutput<'a> {
    ///The actual limit applied (user-specified or default)
    pub applied_limit: i64,
    ///Number of repositories after applying limit
    pub capped_repos: i64,
    #[serde(borrow)]
    pub collections_summary: Vec<get_sync_summary::CollectionSummary<'a>>,
    ///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,
}

impl<'a> LexiconSchema for CollectionSummary<'a> {
    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 type for network.slices.slice.getSyncSummary
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<'de> = GetSyncSummaryOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

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

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

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

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

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

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

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

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

impl<'a, S> CollectionSummaryBuilder<'a, S>
where
    S: collection_summary_state::State,
    S::EstimatedRepos: collection_summary_state::IsSet,
    S::IsExternal: collection_summary_state::IsSet,
    S::Collection: collection_summary_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> CollectionSummary<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> CollectionSummary<'a> {
        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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetSlice<S> {}
    impl<S: State> State for SetSlice<S> {
        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<'a, S: get_sync_summary_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<Vec<CowStr<'a>>>,
        Option<Vec<CowStr<'a>>>,
        Option<Vec<CowStr<'a>>>,
        Option<CowStr<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

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

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

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