// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: events.smokesignal.lfg
//
// 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, open_union};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
/// A Looking For Group record that broadcasts interest in finding activity partners within a geographic area.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "events.smokesignal.lfg",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Lfg<S: BosStr = DefaultStr> {
    ///Whether the LFG is currently active and visible to others.
    pub active: bool,
    ///Record creation timestamp.
    pub created_at: Datetime,
    ///When the LFG expires and is no longer visible.
    pub ends_at: Datetime,
    ///The geographic location for activity partner matching.
    pub location: LfgLocation<S>,
    ///When the LFG becomes active.
    pub starts_at: Datetime,
    ///Interest tags for matching with events and other users.
    pub tags: Vec<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum LfgLocation<S: BosStr = DefaultStr> {}
/// 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 LfgGetRecordOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: Lfg<S>,
}

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

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

#[derive(Debug, Serialize, Deserialize)]
pub struct LfgRecord;
impl XrpcResp for LfgRecord {
    const NSID: &'static str = "events.smokesignal.lfg";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = LfgGetRecordOutput<S>;
    type Err = RecordError;
}

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

impl<S: BosStr> Collection for Lfg<S> {
    const NSID: &'static str = "events.smokesignal.lfg";
    type Record = LfgRecord;
}

impl Collection for LfgRecord {
    const NSID: &'static str = "events.smokesignal.lfg";
    type Record = LfgRecord;
}

impl<S: BosStr> LexiconSchema for Lfg<S> {
    fn nsid() -> &'static str {
        "events.smokesignal.lfg"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_events_smokesignal_lfg()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.tags;
            #[allow(unused_comparisons)]
            if value.len() > 10usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("tags"),
                    max: 10usize,
                    actual: value.len(),
                });
            }
        }
        {
            let value = &self.tags;
            #[allow(unused_comparisons)]
            if value.len() < 1usize {
                return Err(ConstraintError::MinLength {
                    path: ValidationPath::from_field("tags"),
                    min: 1usize,
                    actual: value.len(),
                });
            }
        }
        Ok(())
    }
}

pub mod lfg_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 Active;
        type CreatedAt;
        type EndsAt;
        type Location;
        type StartsAt;
        type Tags;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Active = Unset;
        type CreatedAt = Unset;
        type EndsAt = Unset;
        type Location = Unset;
        type StartsAt = Unset;
        type Tags = Unset;
    }
    ///State transition - sets the `active` field to Set
    pub struct SetActive<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetActive<St> {}
    impl<St: State> State for SetActive<St> {
        type Active = Set<members::active>;
        type CreatedAt = St::CreatedAt;
        type EndsAt = St::EndsAt;
        type Location = St::Location;
        type StartsAt = St::StartsAt;
        type Tags = St::Tags;
    }
    ///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 Active = St::Active;
        type CreatedAt = Set<members::created_at>;
        type EndsAt = St::EndsAt;
        type Location = St::Location;
        type StartsAt = St::StartsAt;
        type Tags = St::Tags;
    }
    ///State transition - sets the `ends_at` field to Set
    pub struct SetEndsAt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetEndsAt<St> {}
    impl<St: State> State for SetEndsAt<St> {
        type Active = St::Active;
        type CreatedAt = St::CreatedAt;
        type EndsAt = Set<members::ends_at>;
        type Location = St::Location;
        type StartsAt = St::StartsAt;
        type Tags = St::Tags;
    }
    ///State transition - sets the `location` field to Set
    pub struct SetLocation<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetLocation<St> {}
    impl<St: State> State for SetLocation<St> {
        type Active = St::Active;
        type CreatedAt = St::CreatedAt;
        type EndsAt = St::EndsAt;
        type Location = Set<members::location>;
        type StartsAt = St::StartsAt;
        type Tags = St::Tags;
    }
    ///State transition - sets the `starts_at` field to Set
    pub struct SetStartsAt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetStartsAt<St> {}
    impl<St: State> State for SetStartsAt<St> {
        type Active = St::Active;
        type CreatedAt = St::CreatedAt;
        type EndsAt = St::EndsAt;
        type Location = St::Location;
        type StartsAt = Set<members::starts_at>;
        type Tags = St::Tags;
    }
    ///State transition - sets the `tags` field to Set
    pub struct SetTags<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetTags<St> {}
    impl<St: State> State for SetTags<St> {
        type Active = St::Active;
        type CreatedAt = St::CreatedAt;
        type EndsAt = St::EndsAt;
        type Location = St::Location;
        type StartsAt = St::StartsAt;
        type Tags = Set<members::tags>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `active` field
        pub struct active(());
        ///Marker type for the `created_at` field
        pub struct created_at(());
        ///Marker type for the `ends_at` field
        pub struct ends_at(());
        ///Marker type for the `location` field
        pub struct location(());
        ///Marker type for the `starts_at` field
        pub struct starts_at(());
        ///Marker type for the `tags` field
        pub struct tags(());
    }
}

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

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

impl<S: BosStr> Lfg<S> {
    /// Create a new builder for this type
    pub fn builder() -> LfgBuilder<lfg_state::Empty, S> {
        LfgBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> LfgBuilder<St, S>
where
    St: lfg_state::State,
    St::Active: lfg_state::IsUnset,
{
    /// Set the `active` field (required)
    pub fn active(
        mut self,
        value: impl Into<bool>,
    ) -> LfgBuilder<lfg_state::SetActive<St>, S> {
        self._fields.0 = Option::Some(value.into());
        LfgBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St, S: BosStr> LfgBuilder<St, S>
where
    St: lfg_state::State,
    St::EndsAt: lfg_state::IsUnset,
{
    /// Set the `endsAt` field (required)
    pub fn ends_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> LfgBuilder<lfg_state::SetEndsAt<St>, S> {
        self._fields.2 = Option::Some(value.into());
        LfgBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> LfgBuilder<St, S>
where
    St: lfg_state::State,
    St::Location: lfg_state::IsUnset,
{
    /// Set the `location` field (required)
    pub fn location(
        mut self,
        value: impl Into<LfgLocation<S>>,
    ) -> LfgBuilder<lfg_state::SetLocation<St>, S> {
        self._fields.3 = Option::Some(value.into());
        LfgBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> LfgBuilder<St, S>
where
    St: lfg_state::State,
    St::StartsAt: lfg_state::IsUnset,
{
    /// Set the `startsAt` field (required)
    pub fn starts_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> LfgBuilder<lfg_state::SetStartsAt<St>, S> {
        self._fields.4 = Option::Some(value.into());
        LfgBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> LfgBuilder<St, S>
where
    St: lfg_state::State,
    St::Tags: lfg_state::IsUnset,
{
    /// Set the `tags` field (required)
    pub fn tags(
        mut self,
        value: impl Into<Vec<S>>,
    ) -> LfgBuilder<lfg_state::SetTags<St>, S> {
        self._fields.5 = Option::Some(value.into());
        LfgBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> LfgBuilder<St, S>
where
    St: lfg_state::State,
    St::Active: lfg_state::IsSet,
    St::CreatedAt: lfg_state::IsSet,
    St::EndsAt: lfg_state::IsSet,
    St::Location: lfg_state::IsSet,
    St::StartsAt: lfg_state::IsSet,
    St::Tags: lfg_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Lfg<S> {
        Lfg {
            active: self._fields.0.unwrap(),
            created_at: self._fields.1.unwrap(),
            ends_at: self._fields.2.unwrap(),
            location: self._fields.3.unwrap(),
            starts_at: self._fields.4.unwrap(),
            tags: self._fields.5.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>>) -> Lfg<S> {
        Lfg {
            active: self._fields.0.unwrap(),
            created_at: self._fields.1.unwrap(),
            ends_at: self._fields.2.unwrap(),
            location: self._fields.3.unwrap(),
            starts_at: self._fields.4.unwrap(),
            tags: self._fields.5.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_events_smokesignal_lfg() -> 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("events.smokesignal.lfg"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "A Looking For Group record that broadcasts interest in finding activity partners within a geographic area.",
                        ),
                    ),
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("location"),
                                SmolStr::new_static("tags"),
                                SmolStr::new_static("startsAt"),
                                SmolStr::new_static("endsAt"),
                                SmolStr::new_static("createdAt"),
                                SmolStr::new_static("active")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("active"),
                                LexObjectProperty::Boolean(LexBoolean {
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Record creation timestamp."),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("endsAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "When the LFG expires and is no longer visible.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("location"),
                                LexObjectProperty::Union(LexRefUnion {
                                    description: Some(
                                        CowStr::new_static(
                                            "The geographic location for activity partner matching.",
                                        ),
                                    ),
                                    refs: vec![
                                        CowStr::new_static("community.lexicon.location#geo"),
                                        CowStr::new_static("community.lexicon.location#hthree")
                                    ],
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("startsAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("When the LFG becomes active."),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("tags"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "Interest tags for matching with events and other users.",
                                        ),
                                    ),
                                    items: LexArrayItem::String(LexString {
                                        max_length: Some(64usize),
                                        max_graphemes: Some(64usize),
                                        ..Default::default()
                                    }),
                                    min_length: Some(1usize),
                                    max_length: Some(10usize),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}