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

#[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::SparklinePoint;
use crate::network_slices::slice::get_sparklines;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetSparklines<'a> {
    ///Time range to fetch data for  Defaults to `"24h"`.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "_default_get_sparklines_duration")]
    #[serde(borrow)]
    pub duration: Option<CowStr<'a>>,
    ///Time interval for data points  Defaults to `"hour"`.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "_default_get_sparklines_interval")]
    #[serde(borrow)]
    pub interval: Option<CowStr<'a>>,
    ///Array of slice AT-URIs to get sparkline data for
    #[serde(borrow)]
    pub slices: Vec<CowStr<'a>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetSparklinesOutput<'a> {
    ///Array of slice sparkline data entries
    #[serde(borrow)]
    pub sparklines: Vec<get_sparklines::SparklineEntry<'a>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct SparklineEntry<'a> {
    ///Array of sparkline data points
    #[serde(borrow)]
    pub points: Vec<SparklinePoint<'a>>,
    ///AT-URI of the slice
    #[serde(borrow)]
    pub slice_uri: CowStr<'a>,
}

/// Response type for network.slices.slice.getSparklines
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<'de> = GetSparklinesOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for GetSparklines<'a> {
    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 type for network.slices.slice.getSparklines
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<'de> = GetSparklines<'de>;
    type Response = GetSparklinesResponse;
}

impl<'a> LexiconSchema for SparklineEntry<'a> {
    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() -> Option<CowStr<'static>> {
    Some(CowStr::from("24h"))
}

fn _default_get_sparklines_interval() -> Option<CowStr<'static>> {
    Some(CowStr::from("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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetSlices<S> {}
    impl<S: State> State for SetSlices<S> {
        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<'a, S: get_sparklines_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<CowStr<'a>>, Option<CowStr<'a>>, Option<Vec<CowStr<'a>>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

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

impl<'a, S> GetSparklinesBuilder<'a, S>
where
    S: get_sparklines_state::State,
    S::Slices: get_sparklines_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> GetSparklines<'a> {
        GetSparklines {
            duration: self._fields.0.or_else(|| Some(CowStr::from("24h"))),
            interval: self._fields.1.or_else(|| Some(CowStr::from("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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> GetSparklines<'a> {
        GetSparklines {
            duration: self._fields.0.or_else(|| Some(CowStr::from("24h"))),
            interval: self._fields.1.or_else(|| Some(CowStr::from("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 SliceUri;
        type Points;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type SliceUri = Unset;
        type Points = Unset;
    }
    ///State transition - sets the `slice_uri` field to Set
    pub struct SetSliceUri<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetSliceUri<S> {}
    impl<S: State> State for SetSliceUri<S> {
        type SliceUri = Set<members::slice_uri>;
        type Points = S::Points;
    }
    ///State transition - sets the `points` field to Set
    pub struct SetPoints<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetPoints<S> {}
    impl<S: State> State for SetPoints<S> {
        type SliceUri = S::SliceUri;
        type Points = Set<members::points>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `slice_uri` field
        pub struct slice_uri(());
        ///Marker type for the `points` field
        pub struct points(());
    }
}

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

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

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

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

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

impl<'a, S> SparklineEntryBuilder<'a, S>
where
    S: sparkline_entry_state::State,
    S::SliceUri: sparkline_entry_state::IsSet,
    S::Points: sparkline_entry_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> SparklineEntry<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> SparklineEntry<'a> {
        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()
    }
}