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

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

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct CollectionStats<'a> {
    ///Collection NSID
    #[serde(borrow)]
    pub collection: Nsid<'a>,
    ///Number of records in this collection
    pub record_count: i64,
    ///Number of unique actors with records in this collection
    pub unique_actors: i64,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Stats<'a> {
    #[serde(borrow)]
    pub slice: CowStr<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct StatsOutput<'a> {
    ///Per-collection statistics
    #[serde(borrow)]
    pub collection_stats: Vec<stats::CollectionStats<'a>>,
    ///List of collection NSIDs indexed in this slice
    #[serde(borrow)]
    pub collections: Vec<Nsid<'a>>,
    ///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,
}

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

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

/// Endpoint type for network.slices.slice.stats
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<'de> = Stats<'de>;
    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 UniqueActors;
        type Collection;
        type RecordCount;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type UniqueActors = Unset;
        type Collection = Unset;
        type RecordCount = Unset;
    }
    ///State transition - sets the `unique_actors` field to Set
    pub struct SetUniqueActors<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetUniqueActors<S> {}
    impl<S: State> State for SetUniqueActors<S> {
        type UniqueActors = Set<members::unique_actors>;
        type Collection = S::Collection;
        type RecordCount = S::RecordCount;
    }
    ///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 UniqueActors = S::UniqueActors;
        type Collection = Set<members::collection>;
        type RecordCount = S::RecordCount;
    }
    ///State transition - sets the `record_count` field to Set
    pub struct SetRecordCount<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetRecordCount<S> {}
    impl<S: State> State for SetRecordCount<S> {
        type UniqueActors = S::UniqueActors;
        type Collection = S::Collection;
        type RecordCount = Set<members::record_count>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `unique_actors` field
        pub struct unique_actors(());
        ///Marker type for the `collection` field
        pub struct collection(());
        ///Marker type for the `record_count` field
        pub struct record_count(());
    }
}

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

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

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

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

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

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

impl<'a, S> CollectionStatsBuilder<'a, S>
where
    S: collection_stats_state::State,
    S::UniqueActors: collection_stats_state::IsSet,
    S::Collection: collection_stats_state::IsSet,
    S::RecordCount: collection_stats_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> CollectionStats<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> CollectionStats<'a> {
        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<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 StatsBuilder<'a, S: stats_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<CowStr<'a>>,),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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