// @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, 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::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::types::value::Data;
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.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "dev.baileytownsend.health.rings",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Rings<S: BosStr = DefaultStr> {
    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,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// 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<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: Rings<S>,
}

impl<S: BosStr> Rings<S> {
    pub fn uri(uri: S) -> Result<RecordUri<S, RingsRecord>, UriError> {
        RecordUri::try_from_uri(AtUri::new(uri)?)
    }
}

/// 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<S: BosStr> = RingsGetRecordOutput<S>;
    type Err = RecordError;
}

impl<S: BosStr> From<RingsGetRecordOutput<S>> for Rings<S> {
    fn from(output: RingsGetRecordOutput<S>) -> Self {
        output.value
    }
}

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

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

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

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

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

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

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

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

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

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

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

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

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

impl<St, S: BosStr> RingsBuilder<St, S>
where
    St: rings_state::State,
    St::CreatedAt: rings_state::IsSet,
    St::Exercise: rings_state::IsSet,
    St::ExerciseGoal: rings_state::IsSet,
    St::Move: rings_state::IsSet,
    St::MoveGoal: rings_state::IsSet,
    St::StandGoal: rings_state::IsSet,
    St::StandHours: rings_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Rings<S> {
        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<SmolStr, Data<S>>) -> Rings<S> {
        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()
    }
}