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

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GetSparklines<S: BosStr = DefaultStr> {
    ///Time range to fetch data for  Defaults to `"24h"`.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "_default_get_sparklines_duration")]
    pub duration: Option<S>,
    ///Time interval for data points  Defaults to `"hour"`.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "_default_get_sparklines_interval")]
    pub interval: Option<S>,
    ///Array of slice AT-URIs to get sparkline data for
    pub slices: Vec<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 GetSparklinesOutput<S: BosStr = DefaultStr> {
    ///Array of slice sparkline data entries
    pub sparklines: Vec<get_sparklines::SparklineEntry<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 SparklineEntry<S: BosStr = DefaultStr> {
    ///Array of sparkline data points
    pub points: Vec<SparklinePoint<S>>,
    ///AT-URI of the slice
    pub slice_uri: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/** Response marker for the `network.slices.slice.getSparklines` procedure.

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

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for GetSparklines<S> {
    const NSID: &'static str = "network.slices.slice.getSparklines";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Response = GetSparklinesResponse;
}

/** Endpoint marker for the `network.slices.slice.getSparklines` procedure.

Path: `/xrpc/network.slices.slice.getSparklines`. The request payload type is `GetSparklines<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
pub struct GetSparklinesRequest;
impl jacquard_common::xrpc::XrpcEndpoint for GetSparklinesRequest {
    const PATH: &'static str = "/xrpc/network.slices.slice.getSparklines";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Request<S: BosStr> = GetSparklines<S>;
    type Response = GetSparklinesResponse;
}

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

fn _default_get_sparklines_duration<S: FromStaticStr>() -> ::core::option::Option<S> {
    Some(S::from_static("24h"))
}

fn _default_get_sparklines_interval<S: FromStaticStr>() -> ::core::option::Option<S> {
    Some(S::from_static("hour"))
}

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

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

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

impl<S: BosStr> GetSparklines<S> {
    /// Create a new builder for this type
    pub fn builder() -> GetSparklinesBuilder<get_sparklines_state::Empty, S> {
        GetSparklinesBuilder::builder()
    }
}

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

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

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

impl<St: get_sparklines_state::State, S: BosStr> GetSparklinesBuilder<St, S> {
    /// Set the `interval` field (optional)
    pub fn interval(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `interval` field to an Option value (optional)
    pub fn maybe_interval(mut self, value: Option<S>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St, S: BosStr> GetSparklinesBuilder<St, S>
where
    St: get_sparklines_state::State,
    St::Slices: get_sparklines_state::IsUnset,
{
    /// Set the `slices` field (required)
    pub fn slices(
        mut self,
        value: impl Into<Vec<S>>,
    ) -> GetSparklinesBuilder<get_sparklines_state::SetSlices<St>, S> {
        self._fields.2 = Option::Some(value.into());
        GetSparklinesBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> GetSparklinesBuilder<St, S>
where
    St: get_sparklines_state::State,
    St::Slices: get_sparklines_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> GetSparklines<S> {
        GetSparklines {
            duration: self._fields.0.or_else(|| Some(S::from_static("24h"))),
            interval: self._fields.1.or_else(|| Some(S::from_static("hour"))),
            slices: 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>>,
    ) -> GetSparklines<S> {
        GetSparklines {
            duration: self._fields.0.or_else(|| Some(S::from_static("24h"))),
            interval: self._fields.1.or_else(|| Some(S::from_static("hour"))),
            slices: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

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

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

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

impl<S: BosStr> SparklineEntry<S> {
    /// Create a new builder for this type
    pub fn builder() -> SparklineEntryBuilder<sparkline_entry_state::Empty, S> {
        SparklineEntryBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> SparklineEntryBuilder<St, S>
where
    St: sparkline_entry_state::State,
    St::Points: sparkline_entry_state::IsUnset,
{
    /// Set the `points` field (required)
    pub fn points(
        mut self,
        value: impl Into<Vec<SparklinePoint<S>>>,
    ) -> SparklineEntryBuilder<sparkline_entry_state::SetPoints<St>, S> {
        self._fields.0 = Option::Some(value.into());
        SparklineEntryBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> SparklineEntryBuilder<St, S>
where
    St: sparkline_entry_state::State,
    St::SliceUri: sparkline_entry_state::IsUnset,
{
    /// Set the `sliceUri` field (required)
    pub fn slice_uri(
        mut self,
        value: impl Into<S>,
    ) -> SparklineEntryBuilder<sparkline_entry_state::SetSliceUri<St>, S> {
        self._fields.1 = Option::Some(value.into());
        SparklineEntryBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> SparklineEntryBuilder<St, S>
where
    St: sparkline_entry_state::State,
    St::Points: sparkline_entry_state::IsSet,
    St::SliceUri: sparkline_entry_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> SparklineEntry<S> {
        SparklineEntry {
            points: self._fields.0.unwrap(),
            slice_uri: self._fields.1.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>>,
    ) -> SparklineEntry<S> {
        SparklineEntry {
            points: self._fields.0.unwrap(),
            slice_uri: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_network_slices_slice_getSparklines() -> 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.getSparklines"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcProcedure(LexXrpcProcedure {
                    input: Some(LexXrpcBody {
                        encoding: CowStr::new_static("application/json"),
                        schema: Some(
                            LexXrpcBodySchema::Object(LexObject {
                                required: Some(vec![SmolStr::new_static("slices")]),
                                properties: {
                                    #[allow(unused_mut)]
                                    let mut map = BTreeMap::new();
                                    map.insert(
                                        SmolStr::new_static("duration"),
                                        LexObjectProperty::String(LexString {
                                            description: Some(
                                                CowStr::new_static("Time range to fetch data for"),
                                            ),
                                            ..Default::default()
                                        }),
                                    );
                                    map.insert(
                                        SmolStr::new_static("interval"),
                                        LexObjectProperty::String(LexString {
                                            description: Some(
                                                CowStr::new_static("Time interval for data points"),
                                            ),
                                            ..Default::default()
                                        }),
                                    );
                                    map.insert(
                                        SmolStr::new_static("slices"),
                                        LexObjectProperty::Array(LexArray {
                                            description: Some(
                                                CowStr::new_static(
                                                    "Array of slice AT-URIs to get sparkline data for",
                                                ),
                                            ),
                                            items: LexArrayItem::String(LexString {
                                                ..Default::default()
                                            }),
                                            ..Default::default()
                                        }),
                                    );
                                    map
                                },
                                ..Default::default()
                            }),
                        ),
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("sparklineEntry"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("sliceUri"),
                            SmolStr::new_static("points")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("points"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static("Array of sparkline data points"),
                                ),
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static(
                                        "network.slices.slice.defs#sparklinePoint",
                                    ),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("sliceUri"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("AT-URI of the slice"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}