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

#[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::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.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Lfg<'a> {
    ///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.
    #[serde(borrow)]
    pub location: LfgLocation<'a>,
    ///When the LFG becomes active.
    pub starts_at: Datetime,
    ///Interest tags for matching with events and other users.
    #[serde(borrow)]
    pub tags: Vec<CowStr<'a>>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum LfgLocation<'a> {}
/// 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<'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: Lfg<'a>,
}

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

/// 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<'de> = LfgGetRecordOutput<'de>;
    type Err<'de> = RecordError<'de>;
}

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

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

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

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

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

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

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

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

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

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

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

impl<'a, S> LfgBuilder<'a, S>
where
    S: lfg_state::State,
    S::StartsAt: lfg_state::IsSet,
    S::Active: lfg_state::IsSet,
    S::Location: lfg_state::IsSet,
    S::CreatedAt: lfg_state::IsSet,
    S::Tags: lfg_state::IsSet,
    S::EndsAt: lfg_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Lfg<'a> {
        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<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
    ) -> Lfg<'a> {
        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()
    }
}