// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: media.ionosphere.defs
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

//! Generated bindings for the `media.ionosphere` Lexicon namespace/module.
pub mod group;
pub mod log;
pub mod programme;
pub mod service;


#[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::string::{AtUri, Datetime, UriValue};
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::media_ionosphere;
/// BearerURI as specified in ETSI TS 103 270
pub type Bearer<S = DefaultStr> = UriValue<S>;
/// Represents the method of accessing a broadcast; i.e. live

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Broadcast<S: BosStr = DefaultStr> {
    pub bearer: media_ionosphere::Bearer<S>,
    ///When used in a list, this can be used to sort the attempted connections or preferred methods  Defaults to `0`.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "_default_broadcast_cost")]
    pub cost: Option<i64>,
    ///The datetime from which this method is available
    #[serde(skip_serializing_if = "Option::is_none")]
    pub from: Option<Datetime>,
    ///Offset in milliseconds compared to other bearers  Defaults to `0`.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "_default_broadcast_offset")]
    pub offset: Option<i64>,
    ///The datetime where this method is no longer available
    #[serde(skip_serializing_if = "Option::is_none")]
    pub until: Option<Datetime>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Credit<S: BosStr = DefaultStr> {
    pub entity: media_ionosphere::Entity<S>,
    ///Self-explanatory, but beware that the expected values may change in future (possibly to match TV-Anytime role classification schema)
    pub role: CreditRole<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Self-explanatory, but beware that the expected values may change in future (possibly to match TV-Anytime role classification schema)

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum CreditRole<S: BosStr = DefaultStr> {
    Creator,
    Contributor,
    Guest,
    Other(S),
}

impl<S: BosStr> CreditRole<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Creator => "creator",
            Self::Contributor => "contributor",
            Self::Guest => "guest",
            Self::Other(s) => s.as_ref(),
        }
    }
    /// Construct from a string-like value, matching known values.
    pub fn from_value(s: S) -> Self {
        match s.as_ref() {
            "creator" => Self::Creator,
            "contributor" => Self::Contributor,
            "guest" => Self::Guest,
            _ => Self::Other(s),
        }
    }
}

impl<S: BosStr> core::fmt::Display for CreditRole<S> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

impl<S: BosStr> AsRef<str> for CreditRole<S> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl<S: BosStr> Serialize for CreditRole<S> {
    fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
    where
        Ser: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for CreditRole<S> {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = S::deserialize(deserializer)?;
        Ok(Self::from_value(s))
    }
}

impl<S: BosStr + Default> Default for CreditRole<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl<S: BosStr> jacquard_common::IntoStatic for CreditRole<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = CreditRole<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            CreditRole::Creator => CreditRole::Creator,
            CreditRole::Contributor => CreditRole::Contributor,
            CreditRole::Guest => CreditRole::Guest,
            CreditRole::Other(v) => CreditRole::Other(v.into_static()),
        }
    }
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Entity<S: BosStr = DefaultStr> {
    pub name: S,
    pub r#type: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// TV-Anytime classification scheme URIs permitted by ETSI TS 102 818 section 5.3
pub type Genre<S = DefaultStr> = UriValue<S>;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Geocoordinates<S: BosStr = DefaultStr> {
    pub latitude: S,
    pub longitude: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Represents membership to a group, optionally with an index

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Membership<S: BosStr = DefaultStr> {
    pub group: AtUri<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub index: Option<i64>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Represents the method of accessing a recording

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Recording<S: BosStr = DefaultStr> {
    pub bearer: media_ionosphere::Bearer<S>,
    ///When used in a list, this can be used to sort the attempted connections or preferred methods  Defaults to `0`.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "_default_recording_cost")]
    pub cost: Option<i64>,
    ///The datetime from which this method is available
    #[serde(skip_serializing_if = "Option::is_none")]
    pub from: Option<Datetime>,
    ///The datetime where this method is no longer available
    #[serde(skip_serializing_if = "Option::is_none")]
    pub until: Option<Datetime>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Track<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub album: Option<S>,
    ///Artists in order of importance to the track
    pub artists: Vec<S>,
    pub title: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> LexiconSchema for Broadcast<S> {
    fn nsid() -> &'static str {
        "media.ionosphere.defs"
    }
    fn def_name() -> &'static str {
        "broadcast"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_media_ionosphere_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Credit<S> {
    fn nsid() -> &'static str {
        "media.ionosphere.defs"
    }
    fn def_name() -> &'static str {
        "credit"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_media_ionosphere_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.role;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 128usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("role"),
                    max: 128usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Entity<S> {
    fn nsid() -> &'static str {
        "media.ionosphere.defs"
    }
    fn def_name() -> &'static str {
        "entity"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_media_ionosphere_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.name;
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 128usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("name"),
                        max: 128usize,
                        actual: count,
                    });
                }
            }
        }
        {
            let value = &self.r#type;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 128usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("type"),
                    max: 128usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Geocoordinates<S> {
    fn nsid() -> &'static str {
        "media.ionosphere.defs"
    }
    fn def_name() -> &'static str {
        "geocoordinates"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_media_ionosphere_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.latitude;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 128usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("latitude"),
                    max: 128usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.longitude;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 128usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("longitude"),
                    max: 128usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Membership<S> {
    fn nsid() -> &'static str {
        "media.ionosphere.defs"
    }
    fn def_name() -> &'static str {
        "membership"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_media_ionosphere_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Recording<S> {
    fn nsid() -> &'static str {
        "media.ionosphere.defs"
    }
    fn def_name() -> &'static str {
        "recording"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_media_ionosphere_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Track<S> {
    fn nsid() -> &'static str {
        "media.ionosphere.defs"
    }
    fn def_name() -> &'static str {
        "track"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_media_ionosphere_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.album {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 256usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("album"),
                    max: 256usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.title;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 256usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("title"),
                    max: 256usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

fn _default_broadcast_cost() -> Option<i64> {
    Some(0i64)
}

fn _default_broadcast_offset() -> Option<i64> {
    Some(0i64)
}

pub mod broadcast_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 Bearer;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Bearer = Unset;
    }
    ///State transition - sets the `bearer` field to Set
    pub struct SetBearer<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetBearer<St> {}
    impl<St: State> State for SetBearer<St> {
        type Bearer = Set<members::bearer>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `bearer` field
        pub struct bearer(());
    }
}

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

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

impl<S: BosStr> Broadcast<S> {
    /// Create a new builder for this type
    pub fn builder() -> BroadcastBuilder<broadcast_state::Empty, S> {
        BroadcastBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> BroadcastBuilder<St, S>
where
    St: broadcast_state::State,
    St::Bearer: broadcast_state::IsUnset,
{
    /// Set the `bearer` field (required)
    pub fn bearer(
        mut self,
        value: impl Into<media_ionosphere::Bearer<S>>,
    ) -> BroadcastBuilder<broadcast_state::SetBearer<St>, S> {
        self._fields.0 = Option::Some(value.into());
        BroadcastBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: broadcast_state::State, S: BosStr> BroadcastBuilder<St, S> {
    /// Set the `cost` field (optional)
    pub fn cost(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `cost` field to an Option value (optional)
    pub fn maybe_cost(mut self, value: Option<i64>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St: broadcast_state::State, S: BosStr> BroadcastBuilder<St, S> {
    /// Set the `from` field (optional)
    pub fn from(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `from` field to an Option value (optional)
    pub fn maybe_from(mut self, value: Option<Datetime>) -> Self {
        self._fields.2 = value;
        self
    }
}

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

impl<St: broadcast_state::State, S: BosStr> BroadcastBuilder<St, S> {
    /// Set the `until` field (optional)
    pub fn until(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `until` field to an Option value (optional)
    pub fn maybe_until(mut self, value: Option<Datetime>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<St, S: BosStr> BroadcastBuilder<St, S>
where
    St: broadcast_state::State,
    St::Bearer: broadcast_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Broadcast<S> {
        Broadcast {
            bearer: self._fields.0.unwrap(),
            cost: self._fields.1.or_else(|| Some(0i64)),
            from: self._fields.2,
            offset: self._fields.3.or_else(|| Some(0i64)),
            until: self._fields.4,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> Broadcast<S> {
        Broadcast {
            bearer: self._fields.0.unwrap(),
            cost: self._fields.1.or_else(|| Some(0i64)),
            from: self._fields.2,
            offset: self._fields.3.or_else(|| Some(0i64)),
            until: self._fields.4,
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_media_ionosphere_defs() -> 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("media.ionosphere.defs"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("bearer"),
                LexUserType::String(LexString {
                    description: Some(
                        CowStr::new_static("BearerURI as specified in ETSI TS 103 270"),
                    ),
                    format: Some(LexStringFormat::Uri),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("broadcast"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Represents the method of accessing a broadcast; i.e. live",
                        ),
                    ),
                    required: Some(vec![SmolStr::new_static("bearer")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("bearer"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("media.ionosphere.defs#bearer"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("cost"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("from"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The datetime from which this method is available",
                                    ),
                                ),
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("offset"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("until"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The datetime where this method is no longer available",
                                    ),
                                ),
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("credit"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("entity"), SmolStr::new_static("role")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("entity"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("media.ionosphere.defs#entity"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("role"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Self-explanatory, but beware that the expected values may change in future (possibly to match TV-Anytime role classification schema)",
                                    ),
                                ),
                                max_length: Some(128usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("entity"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("type"), SmolStr::new_static("name")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("name"),
                            LexObjectProperty::String(LexString {
                                max_graphemes: Some(128usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("type"),
                            LexObjectProperty::String(LexString {
                                max_length: Some(128usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("genre"),
                LexUserType::String(LexString {
                    description: Some(
                        CowStr::new_static(
                            "TV-Anytime classification scheme URIs permitted by ETSI TS 102 818 section 5.3",
                        ),
                    ),
                    format: Some(LexStringFormat::Uri),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("geocoordinates"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("latitude"),
                            SmolStr::new_static("longitude")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("latitude"),
                            LexObjectProperty::String(LexString {
                                max_length: Some(128usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("longitude"),
                            LexObjectProperty::String(LexString {
                                max_length: Some(128usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("membership"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Represents membership to a group, optionally with an index",
                        ),
                    ),
                    required: Some(vec![SmolStr::new_static("group")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("group"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("index"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("recording"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Represents the method of accessing a recording",
                        ),
                    ),
                    required: Some(vec![SmolStr::new_static("bearer")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("bearer"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("media.ionosphere.defs#bearer"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("cost"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("from"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The datetime from which this method is available",
                                    ),
                                ),
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("until"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The datetime where this method is no longer available",
                                    ),
                                ),
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("track"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("title"), SmolStr::new_static("artists")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("album"),
                            LexObjectProperty::String(LexString {
                                max_length: Some(256usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("artists"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static(
                                        "Artists in order of importance to the track",
                                    ),
                                ),
                                items: LexArrayItem::String(LexString {
                                    max_length: Some(256usize),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("title"),
                            LexObjectProperty::String(LexString {
                                max_length: Some(256usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod credit_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 Entity;
        type Role;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Entity = Unset;
        type Role = Unset;
    }
    ///State transition - sets the `entity` field to Set
    pub struct SetEntity<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetEntity<St> {}
    impl<St: State> State for SetEntity<St> {
        type Entity = Set<members::entity>;
        type Role = St::Role;
    }
    ///State transition - sets the `role` field to Set
    pub struct SetRole<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetRole<St> {}
    impl<St: State> State for SetRole<St> {
        type Entity = St::Entity;
        type Role = Set<members::role>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `entity` field
        pub struct entity(());
        ///Marker type for the `role` field
        pub struct role(());
    }
}

/// Builder for constructing an instance of this type.
pub struct CreditBuilder<St: credit_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<media_ionosphere::Entity<S>>, Option<CreditRole<S>>),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Credit<S> {
    /// Create a new builder for this type
    pub fn builder() -> CreditBuilder<credit_state::Empty, S> {
        CreditBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> CreditBuilder<St, S>
where
    St: credit_state::State,
    St::Entity: credit_state::IsUnset,
{
    /// Set the `entity` field (required)
    pub fn entity(
        mut self,
        value: impl Into<media_ionosphere::Entity<S>>,
    ) -> CreditBuilder<credit_state::SetEntity<St>, S> {
        self._fields.0 = Option::Some(value.into());
        CreditBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> CreditBuilder<St, S>
where
    St: credit_state::State,
    St::Role: credit_state::IsUnset,
{
    /// Set the `role` field (required)
    pub fn role(
        mut self,
        value: impl Into<CreditRole<S>>,
    ) -> CreditBuilder<credit_state::SetRole<St>, S> {
        self._fields.1 = Option::Some(value.into());
        CreditBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> CreditBuilder<St, S>
where
    St: credit_state::State,
    St::Entity: credit_state::IsSet,
    St::Role: credit_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Credit<S> {
        Credit {
            entity: self._fields.0.unwrap(),
            role: self._fields.1.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>>) -> Credit<S> {
        Credit {
            entity: self._fields.0.unwrap(),
            role: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod membership_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 Group;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Group = Unset;
    }
    ///State transition - sets the `group` field to Set
    pub struct SetGroup<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetGroup<St> {}
    impl<St: State> State for SetGroup<St> {
        type Group = Set<members::group>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `group` field
        pub struct group(());
    }
}

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

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

impl<S: BosStr> Membership<S> {
    /// Create a new builder for this type
    pub fn builder() -> MembershipBuilder<membership_state::Empty, S> {
        MembershipBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> MembershipBuilder<St, S>
where
    St: membership_state::State,
    St::Group: membership_state::IsUnset,
{
    /// Set the `group` field (required)
    pub fn group(
        mut self,
        value: impl Into<AtUri<S>>,
    ) -> MembershipBuilder<membership_state::SetGroup<St>, S> {
        self._fields.0 = Option::Some(value.into());
        MembershipBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: membership_state::State, S: BosStr> MembershipBuilder<St, S> {
    /// Set the `index` field (optional)
    pub fn index(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `index` field to an Option value (optional)
    pub fn maybe_index(mut self, value: Option<i64>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St, S: BosStr> MembershipBuilder<St, S>
where
    St: membership_state::State,
    St::Group: membership_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Membership<S> {
        Membership {
            group: self._fields.0.unwrap(),
            index: self._fields.1,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> Membership<S> {
        Membership {
            group: self._fields.0.unwrap(),
            index: self._fields.1,
            extra_data: Some(extra_data),
        }
    }
}

fn _default_recording_cost() -> Option<i64> {
    Some(0i64)
}

pub mod recording_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 Bearer;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Bearer = Unset;
    }
    ///State transition - sets the `bearer` field to Set
    pub struct SetBearer<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetBearer<St> {}
    impl<St: State> State for SetBearer<St> {
        type Bearer = Set<members::bearer>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `bearer` field
        pub struct bearer(());
    }
}

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

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

impl<S: BosStr> Recording<S> {
    /// Create a new builder for this type
    pub fn builder() -> RecordingBuilder<recording_state::Empty, S> {
        RecordingBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> RecordingBuilder<St, S>
where
    St: recording_state::State,
    St::Bearer: recording_state::IsUnset,
{
    /// Set the `bearer` field (required)
    pub fn bearer(
        mut self,
        value: impl Into<media_ionosphere::Bearer<S>>,
    ) -> RecordingBuilder<recording_state::SetBearer<St>, S> {
        self._fields.0 = Option::Some(value.into());
        RecordingBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: recording_state::State, S: BosStr> RecordingBuilder<St, S> {
    /// Set the `cost` field (optional)
    pub fn cost(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `cost` field to an Option value (optional)
    pub fn maybe_cost(mut self, value: Option<i64>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St: recording_state::State, S: BosStr> RecordingBuilder<St, S> {
    /// Set the `from` field (optional)
    pub fn from(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `from` field to an Option value (optional)
    pub fn maybe_from(mut self, value: Option<Datetime>) -> Self {
        self._fields.2 = value;
        self
    }
}

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

impl<St, S: BosStr> RecordingBuilder<St, S>
where
    St: recording_state::State,
    St::Bearer: recording_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Recording<S> {
        Recording {
            bearer: self._fields.0.unwrap(),
            cost: self._fields.1.or_else(|| Some(0i64)),
            from: self._fields.2,
            until: self._fields.3,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> Recording<S> {
        Recording {
            bearer: self._fields.0.unwrap(),
            cost: self._fields.1.or_else(|| Some(0i64)),
            from: self._fields.2,
            until: self._fields.3,
            extra_data: Some(extra_data),
        }
    }
}

pub mod track_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 Artists;
        type Title;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Artists = Unset;
        type Title = Unset;
    }
    ///State transition - sets the `artists` field to Set
    pub struct SetArtists<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetArtists<St> {}
    impl<St: State> State for SetArtists<St> {
        type Artists = Set<members::artists>;
        type Title = St::Title;
    }
    ///State transition - sets the `title` field to Set
    pub struct SetTitle<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetTitle<St> {}
    impl<St: State> State for SetTitle<St> {
        type Artists = St::Artists;
        type Title = Set<members::title>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `artists` field
        pub struct artists(());
        ///Marker type for the `title` field
        pub struct title(());
    }
}

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

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

impl<S: BosStr> Track<S> {
    /// Create a new builder for this type
    pub fn builder() -> TrackBuilder<track_state::Empty, S> {
        TrackBuilder::builder()
    }
}

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

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

impl<St: track_state::State, S: BosStr> TrackBuilder<St, S> {
    /// Set the `album` field (optional)
    pub fn album(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `album` field to an Option value (optional)
    pub fn maybe_album(mut self, value: Option<S>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St, S: BosStr> TrackBuilder<St, S>
where
    St: track_state::State,
    St::Artists: track_state::IsUnset,
{
    /// Set the `artists` field (required)
    pub fn artists(
        mut self,
        value: impl Into<Vec<S>>,
    ) -> TrackBuilder<track_state::SetArtists<St>, S> {
        self._fields.1 = Option::Some(value.into());
        TrackBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> TrackBuilder<St, S>
where
    St: track_state::State,
    St::Title: track_state::IsUnset,
{
    /// Set the `title` field (required)
    pub fn title(
        mut self,
        value: impl Into<S>,
    ) -> TrackBuilder<track_state::SetTitle<St>, S> {
        self._fields.2 = Option::Some(value.into());
        TrackBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> TrackBuilder<St, S>
where
    St: track_state::State,
    St::Artists: track_state::IsSet,
    St::Title: track_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Track<S> {
        Track {
            album: self._fields.0,
            artists: self._fields.1.unwrap(),
            title: self._fields.2.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>>) -> Track<S> {
        Track {
            album: self._fields.0,
            artists: self._fields.1.unwrap(),
            title: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}