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

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct CollectionStats<S: BosStr = DefaultStr> {
    ///Collection NSID
    pub collection: Nsid<S>,
    ///Number of records in this collection
    pub record_count: i64,
    ///Number of unique actors with records in this collection
    pub unique_actors: i64,
    #[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 Stats<S: BosStr = DefaultStr> {
    pub slice: S,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct StatsOutput<S: BosStr = DefaultStr> {
    ///Per-collection statistics
    pub collection_stats: Vec<stats::CollectionStats<S>>,
    ///List of collection NSIDs indexed in this slice
    pub collections: Vec<Nsid<S>>,
    ///Total number of unique actors indexed in this slice
    pub total_actors: i64,
    ///Total number of lexicons defined for this slice
    pub total_lexicons: i64,
    ///Total number of records indexed in this slice
    pub total_records: i64,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

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

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

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

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

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

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

pub mod collection_stats_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 RecordCount;
        type UniqueActors;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Collection = Unset;
        type RecordCount = Unset;
        type UniqueActors = 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 RecordCount = St::RecordCount;
        type UniqueActors = St::UniqueActors;
    }
    ///State transition - sets the `record_count` field to Set
    pub struct SetRecordCount<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetRecordCount<St> {}
    impl<St: State> State for SetRecordCount<St> {
        type Collection = St::Collection;
        type RecordCount = Set<members::record_count>;
        type UniqueActors = St::UniqueActors;
    }
    ///State transition - sets the `unique_actors` field to Set
    pub struct SetUniqueActors<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetUniqueActors<St> {}
    impl<St: State> State for SetUniqueActors<St> {
        type Collection = St::Collection;
        type RecordCount = St::RecordCount;
        type UniqueActors = Set<members::unique_actors>;
    }
    /// 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 `record_count` field
        pub struct record_count(());
        ///Marker type for the `unique_actors` field
        pub struct unique_actors(());
    }
}

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

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

impl<S: BosStr> CollectionStats<S> {
    /// Create a new builder for this type
    pub fn builder() -> CollectionStatsBuilder<collection_stats_state::Empty, S> {
        CollectionStatsBuilder::builder()
    }
}

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

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

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

impl<St, S: BosStr> CollectionStatsBuilder<St, S>
where
    St: collection_stats_state::State,
    St::RecordCount: collection_stats_state::IsUnset,
{
    /// Set the `recordCount` field (required)
    pub fn record_count(
        mut self,
        value: impl Into<i64>,
    ) -> CollectionStatsBuilder<collection_stats_state::SetRecordCount<St>, S> {
        self._fields.1 = Option::Some(value.into());
        CollectionStatsBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> CollectionStatsBuilder<St, S>
where
    St: collection_stats_state::State,
    St::UniqueActors: collection_stats_state::IsUnset,
{
    /// Set the `uniqueActors` field (required)
    pub fn unique_actors(
        mut self,
        value: impl Into<i64>,
    ) -> CollectionStatsBuilder<collection_stats_state::SetUniqueActors<St>, S> {
        self._fields.2 = Option::Some(value.into());
        CollectionStatsBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> CollectionStatsBuilder<St, S>
where
    St: collection_stats_state::State,
    St::Collection: collection_stats_state::IsSet,
    St::RecordCount: collection_stats_state::IsSet,
    St::UniqueActors: collection_stats_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> CollectionStats<S> {
        CollectionStats {
            collection: self._fields.0.unwrap(),
            record_count: self._fields.1.unwrap(),
            unique_actors: 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>>,
    ) -> CollectionStats<S> {
        CollectionStats {
            collection: self._fields.0.unwrap(),
            record_count: self._fields.1.unwrap(),
            unique_actors: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_network_slices_slice_stats() -> 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.stats"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("collectionStats"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("collection"),
                            SmolStr::new_static("recordCount"),
                            SmolStr::new_static("uniqueActors")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("collection"),
                            LexObjectProperty::String(LexString {
                                description: Some(CowStr::new_static("Collection NSID")),
                                format: Some(LexStringFormat::Nsid),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("recordCount"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("uniqueActors"),
                            LexObjectProperty::Integer(LexInteger {
                                ..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("slice"),
                                    LexXrpcParametersProperty::String(LexString {
                                        description: Some(
                                            CowStr::new_static(
                                                "AT-URI of the slice to get statistics for",
                                            ),
                                        ),
                                        ..Default::default()
                                    }),
                                );
                                map
                            },
                            ..Default::default()
                        }),
                    ),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod stats_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 StatsBuilder<St: stats_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<S>,),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Stats<S> {
    /// Create a new builder for this type
    pub fn builder() -> StatsBuilder<stats_state::Empty, S> {
        StatsBuilder::builder()
    }
}

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

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

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

impl<St, S: BosStr> StatsBuilder<St, S>
where
    St: stats_state::State,
    St::Slice: stats_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Stats<S> {
        Stats {
            slice: self._fields.0.unwrap(),
        }
    }
}