// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: dev.baileytownsend.health.rings
//
// 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::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::xrpc::XrpcResp;
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};
/// A record of daily activity rings (Apple Fitness), including move, exercise, and stand goals.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Rings<'a> {
    pub created_at: Datetime,
    ///The total minutes of exercise completed.
    pub exercise: i64,
    ///The daily exercise goal in minutes.
    pub exercise_goal: i64,
    ///The total active calories burned for the day.
    pub r#move: i64,
    ///The daily move goal in calories.
    pub move_goal: i64,
    ///The daily stand goal in hours.
    pub stand_goal: i64,
    ///The number of hours the user stood up and moved around.
    pub stand_hours: i64,
}

/// Typed wrapper for GetRecord response with this collection's record type.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct RingsGetRecordOutput<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cid: Option<Cid<'a>>,
    #[serde(borrow)]
    pub uri: AtUri<'a>,
    #[serde(borrow)]
    pub value: Rings<'a>,
}

impl<'a> Rings<'a> {
    pub fn uri(
        uri: impl Into<CowStr<'a>>,
    ) -> Result<RecordUri<'a, RingsRecord>, UriError> {
        RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
    }
}

/// Marker type for deserializing records from this collection.

#[derive(Debug, Serialize, Deserialize)]
pub struct RingsRecord;
impl XrpcResp for RingsRecord {
    const NSID: &'static str = "dev.baileytownsend.health.rings";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = RingsGetRecordOutput<'de>;
    type Err<'de> = RecordError<'de>;
}

impl From<RingsGetRecordOutput<'_>> for Rings<'_> {
    fn from(output: RingsGetRecordOutput<'_>) -> Self {
        use jacquard_common::IntoStatic;
        output.value.into_static()
    }
}

impl Collection for Rings<'_> {
    const NSID: &'static str = "dev.baileytownsend.health.rings";
    type Record = RingsRecord;
}

impl Collection for RingsRecord {
    const NSID: &'static str = "dev.baileytownsend.health.rings";
    type Record = RingsRecord;
}

impl<'a> LexiconSchema for Rings<'a> {
    fn nsid() -> &'static str {
        "dev.baileytownsend.health.rings"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_dev_baileytownsend_health_rings()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

pub mod rings_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 Exercise;
        type StandGoal;
        type ExerciseGoal;
        type MoveGoal;
        type Move;
        type StandHours;
        type CreatedAt;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Exercise = Unset;
        type StandGoal = Unset;
        type ExerciseGoal = Unset;
        type MoveGoal = Unset;
        type Move = Unset;
        type StandHours = Unset;
        type CreatedAt = Unset;
    }
    ///State transition - sets the `exercise` field to Set
    pub struct SetExercise<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetExercise<S> {}
    impl<S: State> State for SetExercise<S> {
        type Exercise = Set<members::exercise>;
        type StandGoal = S::StandGoal;
        type ExerciseGoal = S::ExerciseGoal;
        type MoveGoal = S::MoveGoal;
        type Move = S::Move;
        type StandHours = S::StandHours;
        type CreatedAt = S::CreatedAt;
    }
    ///State transition - sets the `stand_goal` field to Set
    pub struct SetStandGoal<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetStandGoal<S> {}
    impl<S: State> State for SetStandGoal<S> {
        type Exercise = S::Exercise;
        type StandGoal = Set<members::stand_goal>;
        type ExerciseGoal = S::ExerciseGoal;
        type MoveGoal = S::MoveGoal;
        type Move = S::Move;
        type StandHours = S::StandHours;
        type CreatedAt = S::CreatedAt;
    }
    ///State transition - sets the `exercise_goal` field to Set
    pub struct SetExerciseGoal<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetExerciseGoal<S> {}
    impl<S: State> State for SetExerciseGoal<S> {
        type Exercise = S::Exercise;
        type StandGoal = S::StandGoal;
        type ExerciseGoal = Set<members::exercise_goal>;
        type MoveGoal = S::MoveGoal;
        type Move = S::Move;
        type StandHours = S::StandHours;
        type CreatedAt = S::CreatedAt;
    }
    ///State transition - sets the `move_goal` field to Set
    pub struct SetMoveGoal<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetMoveGoal<S> {}
    impl<S: State> State for SetMoveGoal<S> {
        type Exercise = S::Exercise;
        type StandGoal = S::StandGoal;
        type ExerciseGoal = S::ExerciseGoal;
        type MoveGoal = Set<members::move_goal>;
        type Move = S::Move;
        type StandHours = S::StandHours;
        type CreatedAt = S::CreatedAt;
    }
    ///State transition - sets the `move` field to Set
    pub struct SetMove<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetMove<S> {}
    impl<S: State> State for SetMove<S> {
        type Exercise = S::Exercise;
        type StandGoal = S::StandGoal;
        type ExerciseGoal = S::ExerciseGoal;
        type MoveGoal = S::MoveGoal;
        type Move = Set<members::r#move>;
        type StandHours = S::StandHours;
        type CreatedAt = S::CreatedAt;
    }
    ///State transition - sets the `stand_hours` field to Set
    pub struct SetStandHours<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetStandHours<S> {}
    impl<S: State> State for SetStandHours<S> {
        type Exercise = S::Exercise;
        type StandGoal = S::StandGoal;
        type ExerciseGoal = S::ExerciseGoal;
        type MoveGoal = S::MoveGoal;
        type Move = S::Move;
        type StandHours = Set<members::stand_hours>;
        type CreatedAt = S::CreatedAt;
    }
    ///State transition - sets the `created_at` field to Set
    pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
    impl<S: State> State for SetCreatedAt<S> {
        type Exercise = S::Exercise;
        type StandGoal = S::StandGoal;
        type ExerciseGoal = S::ExerciseGoal;
        type MoveGoal = S::MoveGoal;
        type Move = S::Move;
        type StandHours = S::StandHours;
        type CreatedAt = Set<members::created_at>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `exercise` field
        pub struct exercise(());
        ///Marker type for the `stand_goal` field
        pub struct stand_goal(());
        ///Marker type for the `exercise_goal` field
        pub struct exercise_goal(());
        ///Marker type for the `move_goal` field
        pub struct move_goal(());
        ///Marker type for the `move` field
        pub struct r#move(());
        ///Marker type for the `stand_hours` field
        pub struct stand_hours(());
        ///Marker type for the `created_at` field
        pub struct created_at(());
    }
}

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

impl<'a> Rings<'a> {
    /// Create a new builder for this type
    pub fn new() -> RingsBuilder<'a, rings_state::Empty> {
        RingsBuilder::new()
    }
}

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

impl<'a, S> RingsBuilder<'a, S>
where
    S: rings_state::State,
    S::CreatedAt: rings_state::IsUnset,
{
    /// Set the `createdAt` field (required)
    pub fn created_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> RingsBuilder<'a, rings_state::SetCreatedAt<S>> {
        self._fields.0 = Option::Some(value.into());
        RingsBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> RingsBuilder<'a, S>
where
    S: rings_state::State,
    S::Exercise: rings_state::IsUnset,
{
    /// Set the `exercise` field (required)
    pub fn exercise(
        mut self,
        value: impl Into<i64>,
    ) -> RingsBuilder<'a, rings_state::SetExercise<S>> {
        self._fields.1 = Option::Some(value.into());
        RingsBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> RingsBuilder<'a, S>
where
    S: rings_state::State,
    S::ExerciseGoal: rings_state::IsUnset,
{
    /// Set the `exerciseGoal` field (required)
    pub fn exercise_goal(
        mut self,
        value: impl Into<i64>,
    ) -> RingsBuilder<'a, rings_state::SetExerciseGoal<S>> {
        self._fields.2 = Option::Some(value.into());
        RingsBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> RingsBuilder<'a, S>
where
    S: rings_state::State,
    S::Move: rings_state::IsUnset,
{
    /// Set the `move` field (required)
    pub fn r#move(
        mut self,
        value: impl Into<i64>,
    ) -> RingsBuilder<'a, rings_state::SetMove<S>> {
        self._fields.3 = Option::Some(value.into());
        RingsBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> RingsBuilder<'a, S>
where
    S: rings_state::State,
    S::MoveGoal: rings_state::IsUnset,
{
    /// Set the `moveGoal` field (required)
    pub fn move_goal(
        mut self,
        value: impl Into<i64>,
    ) -> RingsBuilder<'a, rings_state::SetMoveGoal<S>> {
        self._fields.4 = Option::Some(value.into());
        RingsBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> RingsBuilder<'a, S>
where
    S: rings_state::State,
    S::StandGoal: rings_state::IsUnset,
{
    /// Set the `standGoal` field (required)
    pub fn stand_goal(
        mut self,
        value: impl Into<i64>,
    ) -> RingsBuilder<'a, rings_state::SetStandGoal<S>> {
        self._fields.5 = Option::Some(value.into());
        RingsBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> RingsBuilder<'a, S>
where
    S: rings_state::State,
    S::StandHours: rings_state::IsUnset,
{
    /// Set the `standHours` field (required)
    pub fn stand_hours(
        mut self,
        value: impl Into<i64>,
    ) -> RingsBuilder<'a, rings_state::SetStandHours<S>> {
        self._fields.6 = Option::Some(value.into());
        RingsBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> RingsBuilder<'a, S>
where
    S: rings_state::State,
    S::Exercise: rings_state::IsSet,
    S::StandGoal: rings_state::IsSet,
    S::ExerciseGoal: rings_state::IsSet,
    S::MoveGoal: rings_state::IsSet,
    S::Move: rings_state::IsSet,
    S::StandHours: rings_state::IsSet,
    S::CreatedAt: rings_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Rings<'a> {
        Rings {
            created_at: self._fields.0.unwrap(),
            exercise: self._fields.1.unwrap(),
            exercise_goal: self._fields.2.unwrap(),
            r#move: self._fields.3.unwrap(),
            move_goal: self._fields.4.unwrap(),
            stand_goal: self._fields.5.unwrap(),
            stand_hours: self._fields.6.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>,
        >,
    ) -> Rings<'a> {
        Rings {
            created_at: self._fields.0.unwrap(),
            exercise: self._fields.1.unwrap(),
            exercise_goal: self._fields.2.unwrap(),
            r#move: self._fields.3.unwrap(),
            move_goal: self._fields.4.unwrap(),
            stand_goal: self._fields.5.unwrap(),
            stand_hours: self._fields.6.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_dev_baileytownsend_health_rings() -> 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("dev.baileytownsend.health.rings"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "A record of daily activity rings (Apple Fitness), including move, exercise, and stand goals.",
                        ),
                    ),
                    key: Some(CowStr::new_static("any")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("move"),
                                SmolStr::new_static("moveGoal"),
                                SmolStr::new_static("exercise"),
                                SmolStr::new_static("exerciseGoal"),
                                SmolStr::new_static("standHours"),
                                SmolStr::new_static("standGoal"),
                                SmolStr::new_static("createdAt")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("exercise"),
                                LexObjectProperty::Integer(LexInteger {
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("exerciseGoal"),
                                LexObjectProperty::Integer(LexInteger {
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("move"),
                                LexObjectProperty::Integer(LexInteger {
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("moveGoal"),
                                LexObjectProperty::Integer(LexInteger {
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("standGoal"),
                                LexObjectProperty::Integer(LexInteger {
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("standHours"),
                                LexObjectProperty::Integer(LexInteger {
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}