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

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "dev.baileytownsend.health.workout",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Workout<S: BosStr = DefaultStr> {
    ///Type of activity. Walking, running, weights, etc.
    pub activity: S,
    ///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")]
    pub distance: Option<S>,
    ///How long the workout lasted in minutes.
    pub duration: S,
    pub end_time: Datetime,
    pub start_time: Datetime,
    #[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 WorkoutGetRecordOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: Workout<S>,
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

impl<St, S: BosStr> WorkoutBuilder<St, S>
where
    St: workout_state::State,
    St::Activity: workout_state::IsSet,
    St::CaloriesBurned: workout_state::IsSet,
    St::CreatedAt: workout_state::IsSet,
    St::Duration: workout_state::IsSet,
    St::EndTime: workout_state::IsSet,
    St::StartTime: workout_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Workout<S> {
        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<SmolStr, Data<S>>) -> Workout<S> {
        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()
    }
}