// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: dev.baileytownsend.health.workout
//
// 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};

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Workout<'a> {
    ///Type of activity. Walking, running, weights, etc.
    #[serde(borrow)]
    pub activity: CowStr<'a>,
    ///Active calories burned during the workout.
    pub calories_burned: i64,
    pub created_at: Datetime,
    ///Distance covered during the workout (optional).
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub distance: Option<CowStr<'a>>,
    ///How long the workout lasted in minutes.
    #[serde(borrow)]
    pub duration: CowStr<'a>,
    pub end_time: Datetime,
    pub start_time: Datetime,
}

/// 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 WorkoutGetRecordOutput<'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: Workout<'a>,
}

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

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

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

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

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

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

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

pub mod workout_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 Activity;
        type StartTime;
        type CaloriesBurned;
        type EndTime;
        type CreatedAt;
        type Duration;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Activity = Unset;
        type StartTime = Unset;
        type CaloriesBurned = Unset;
        type EndTime = Unset;
        type CreatedAt = Unset;
        type Duration = Unset;
    }
    ///State transition - sets the `activity` field to Set
    pub struct SetActivity<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetActivity<S> {}
    impl<S: State> State for SetActivity<S> {
        type Activity = Set<members::activity>;
        type StartTime = S::StartTime;
        type CaloriesBurned = S::CaloriesBurned;
        type EndTime = S::EndTime;
        type CreatedAt = S::CreatedAt;
        type Duration = S::Duration;
    }
    ///State transition - sets the `start_time` field to Set
    pub struct SetStartTime<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetStartTime<S> {}
    impl<S: State> State for SetStartTime<S> {
        type Activity = S::Activity;
        type StartTime = Set<members::start_time>;
        type CaloriesBurned = S::CaloriesBurned;
        type EndTime = S::EndTime;
        type CreatedAt = S::CreatedAt;
        type Duration = S::Duration;
    }
    ///State transition - sets the `calories_burned` field to Set
    pub struct SetCaloriesBurned<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCaloriesBurned<S> {}
    impl<S: State> State for SetCaloriesBurned<S> {
        type Activity = S::Activity;
        type StartTime = S::StartTime;
        type CaloriesBurned = Set<members::calories_burned>;
        type EndTime = S::EndTime;
        type CreatedAt = S::CreatedAt;
        type Duration = S::Duration;
    }
    ///State transition - sets the `end_time` field to Set
    pub struct SetEndTime<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetEndTime<S> {}
    impl<S: State> State for SetEndTime<S> {
        type Activity = S::Activity;
        type StartTime = S::StartTime;
        type CaloriesBurned = S::CaloriesBurned;
        type EndTime = Set<members::end_time>;
        type CreatedAt = S::CreatedAt;
        type Duration = S::Duration;
    }
    ///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 Activity = S::Activity;
        type StartTime = S::StartTime;
        type CaloriesBurned = S::CaloriesBurned;
        type EndTime = S::EndTime;
        type CreatedAt = Set<members::created_at>;
        type Duration = S::Duration;
    }
    ///State transition - sets the `duration` field to Set
    pub struct SetDuration<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetDuration<S> {}
    impl<S: State> State for SetDuration<S> {
        type Activity = S::Activity;
        type StartTime = S::StartTime;
        type CaloriesBurned = S::CaloriesBurned;
        type EndTime = S::EndTime;
        type CreatedAt = S::CreatedAt;
        type Duration = Set<members::duration>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `activity` field
        pub struct activity(());
        ///Marker type for the `start_time` field
        pub struct start_time(());
        ///Marker type for the `calories_burned` field
        pub struct calories_burned(());
        ///Marker type for the `end_time` field
        pub struct end_time(());
        ///Marker type for the `created_at` field
        pub struct created_at(());
        ///Marker type for the `duration` field
        pub struct duration(());
    }
}

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

impl<'a> Workout<'a> {
    /// Create a new builder for this type
    pub fn new() -> WorkoutBuilder<'a, workout_state::Empty> {
        WorkoutBuilder::new()
    }
}

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

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

impl<'a, S> WorkoutBuilder<'a, S>
where
    S: workout_state::State,
    S::CaloriesBurned: workout_state::IsUnset,
{
    /// Set the `caloriesBurned` field (required)
    pub fn calories_burned(
        mut self,
        value: impl Into<i64>,
    ) -> WorkoutBuilder<'a, workout_state::SetCaloriesBurned<S>> {
        self._fields.1 = Option::Some(value.into());
        WorkoutBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

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

impl<'a, S: workout_state::State> WorkoutBuilder<'a, S> {
    /// Set the `distance` field (optional)
    pub fn distance(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `distance` field to an Option value (optional)
    pub fn maybe_distance(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<'a, S> WorkoutBuilder<'a, S>
where
    S: workout_state::State,
    S::Duration: workout_state::IsUnset,
{
    /// Set the `duration` field (required)
    pub fn duration(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> WorkoutBuilder<'a, workout_state::SetDuration<S>> {
        self._fields.4 = Option::Some(value.into());
        WorkoutBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> WorkoutBuilder<'a, S>
where
    S: workout_state::State,
    S::EndTime: workout_state::IsUnset,
{
    /// Set the `endTime` field (required)
    pub fn end_time(
        mut self,
        value: impl Into<Datetime>,
    ) -> WorkoutBuilder<'a, workout_state::SetEndTime<S>> {
        self._fields.5 = Option::Some(value.into());
        WorkoutBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> WorkoutBuilder<'a, S>
where
    S: workout_state::State,
    S::StartTime: workout_state::IsUnset,
{
    /// Set the `startTime` field (required)
    pub fn start_time(
        mut self,
        value: impl Into<Datetime>,
    ) -> WorkoutBuilder<'a, workout_state::SetStartTime<S>> {
        self._fields.6 = Option::Some(value.into());
        WorkoutBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> WorkoutBuilder<'a, S>
where
    S: workout_state::State,
    S::Activity: workout_state::IsSet,
    S::StartTime: workout_state::IsSet,
    S::CaloriesBurned: workout_state::IsSet,
    S::EndTime: workout_state::IsSet,
    S::CreatedAt: workout_state::IsSet,
    S::Duration: workout_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Workout<'a> {
        Workout {
            activity: self._fields.0.unwrap(),
            calories_burned: self._fields.1.unwrap(),
            created_at: self._fields.2.unwrap(),
            distance: self._fields.3,
            duration: self._fields.4.unwrap(),
            end_time: self._fields.5.unwrap(),
            start_time: 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>,
        >,
    ) -> Workout<'a> {
        Workout {
            activity: self._fields.0.unwrap(),
            calories_burned: self._fields.1.unwrap(),
            created_at: self._fields.2.unwrap(),
            distance: self._fields.3,
            duration: self._fields.4.unwrap(),
            end_time: self._fields.5.unwrap(),
            start_time: self._fields.6.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_dev_baileytownsend_health_workout() -> 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.workout"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    key: Some(CowStr::new_static("any")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("activity"),
                                SmolStr::new_static("caloriesBurned"),
                                SmolStr::new_static("duration"),
                                SmolStr::new_static("startTime"),
                                SmolStr::new_static("endTime"),
                                SmolStr::new_static("createdAt")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("activity"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Type of activity. Walking, running, weights, etc.",
                                        ),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("caloriesBurned"),
                                LexObjectProperty::Integer(LexInteger {
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("distance"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Distance covered during the workout (optional).",
                                        ),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("duration"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "How long the workout lasted in minutes.",
                                        ),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("endTime"),
                                LexObjectProperty::String(LexString {
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("startTime"),
                                LexObjectProperty::String(LexString {
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}