// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: org.atpodcasting.episode
//
// 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::blob::BlobRef;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime, Language, UriValue};
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};
use crate::org_atpodcasting::PodcastRef;
use crate::org_atpodcasting::episode;
/// Reference to an externally hosted chapters file.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ChaptersRef<S: BosStr = DefaultStr> {
    ///MIME type of the chapters file (e.g. application/json+chapters).
    pub mime_type: S,
    ///URL of the chapters file.
    pub url: UriValue<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// A podcast episode. Record key is a UUIDv5 derived from the podcast GUID (as namespace) and the episode's feedItemGuid (as name), enabling deterministic lookup from RSS feed metadata.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "org.atpodcasting.episode",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Episode<S: BosStr = DefaultStr> {
    ///Alternate versions of the episode media (e.g. different formats or audio-only versions of video episodes).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub alternate_media: Option<Vec<episode::MediaRef<S>>>,
    ///Episode-specific artwork. Overrides the podcast artwork when set. Recommended: 1400x1400 to 3000x3000 pixels, square, no alpha channel.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub artwork: Option<BlobRef<S>>,
    ///Reference to an externally hosted chapters file.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub chapters: Option<episode::ChaptersRef<S>>,
    ///When the episode record was created.
    pub created_at: Datetime,
    ///A description or show notes for the episode.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<S>,
    ///Duration of the episode in seconds.
    pub duration: i64,
    ///Episode number within its season or the overall series.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub episode_number: Option<i64>,
    ///The type of episode. Defaults to full.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub episode_type: Option<EpisodeEpisodeType<S>>,
    ///Whether the episode contains explicit content. Overrides the podcast-level setting when set.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub explicit: Option<bool>,
    ///The original feed item identifier. Must match the <guid> element of the corresponding RSS feed item. The record key (rkey) is derived from this value as uuid5(<podcast:guid>, feedItemGuid).
    pub feed_item_guid: S,
    ///URL of a companion webpage or show notes page for the episode.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub link: Option<UriValue<S>>,
    ///The primary media file for the episode.
    pub media: episode::MediaRef<S>,
    ///Identifies the parent podcast. Since episodes live in the same repository as their podcast, the AT URI is always derivable from the episode's DID and the podcastGuid.
    pub podcast: PodcastRef<S>,
    ///When the episode was published.
    pub published_at: Datetime,
    ///Season number of the episode.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub season_number: Option<i64>,
    ///The title of the episode.
    pub title: S,
    ///References to externally hosted transcript files (e.g. VTT, SRT, JSON). Multiple entries allow providing transcripts in different formats.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub transcript: Option<Vec<episode::TranscriptRef<S>>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// The type of episode. Defaults to full.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum EpisodeEpisodeType<S: BosStr = DefaultStr> {
    Full,
    Trailer,
    Bonus,
    Other(S),
}

impl<S: BosStr> EpisodeEpisodeType<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Full => "full",
            Self::Trailer => "trailer",
            Self::Bonus => "bonus",
            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() {
            "full" => Self::Full,
            "trailer" => Self::Trailer,
            "bonus" => Self::Bonus,
            _ => Self::Other(s),
        }
    }
}

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

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

impl<S: BosStr> Serialize for EpisodeEpisodeType<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 EpisodeEpisodeType<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 EpisodeEpisodeType<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl<S: BosStr> jacquard_common::IntoStatic for EpisodeEpisodeType<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = EpisodeEpisodeType<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            EpisodeEpisodeType::Full => EpisodeEpisodeType::Full,
            EpisodeEpisodeType::Trailer => EpisodeEpisodeType::Trailer,
            EpisodeEpisodeType::Bonus => EpisodeEpisodeType::Bonus,
            EpisodeEpisodeType::Other(v) => EpisodeEpisodeType::Other(v.into_static()),
        }
    }
}

/// 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 EpisodeGetRecordOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: Episode<S>,
}

/// Reference to an externally hosted media file.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct MediaRef<S: BosStr = DefaultStr> {
    ///MIME type of the media file (e.g. audio/mpeg, video/mp4).
    pub mime_type: S,
    ///URL of the media file.
    pub url: UriValue<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Reference to an externally hosted transcript file.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct TranscriptRef<S: BosStr = DefaultStr> {
    ///Language of the transcript (ISO 639-1 two-letter code, e.g. 'en', 'es', 'pt').
    #[serde(skip_serializing_if = "Option::is_none")]
    pub language: Option<Language>,
    ///MIME type of the transcript file (e.g. text/vtt, application/x-subrip, application/json).
    pub mime_type: S,
    ///URL of the transcript file.
    pub url: UriValue<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

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

impl<S: BosStr> LexiconSchema for ChaptersRef<S> {
    fn nsid() -> &'static str {
        "org.atpodcasting.episode"
    }
    fn def_name() -> &'static str {
        "chaptersRef"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_org_atpodcasting_episode()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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

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

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

impl<S: BosStr> Collection for Episode<S> {
    const NSID: &'static str = "org.atpodcasting.episode";
    type Record = EpisodeRecord;
}

impl Collection for EpisodeRecord {
    const NSID: &'static str = "org.atpodcasting.episode";
    type Record = EpisodeRecord;
}

impl<S: BosStr> LexiconSchema for Episode<S> {
    fn nsid() -> &'static str {
        "org.atpodcasting.episode"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_org_atpodcasting_episode()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.alternate_media {
            #[allow(unused_comparisons)]
            if value.len() > 10usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("alternate_media"),
                    max: 10usize,
                    actual: value.len(),
                });
            }
        }
        if let Some(ref value) = self.artwork {
            {
                let size = value.blob().size;
                if size > 5000000usize {
                    return Err(ConstraintError::BlobTooLarge {
                        path: ValidationPath::from_field("artwork"),
                        max: 5000000usize,
                        actual: size,
                    });
                }
            }
        }
        if let Some(ref value) = self.artwork {
            {
                let mime = value.blob().mime_type.as_str();
                let accepted: &[&str] = &["image/png", "image/jpeg"];
                let matched = accepted
                    .iter()
                    .any(|pattern| {
                        if *pattern == "*/*" {
                            true
                        } else if pattern.ends_with("/*") {
                            let prefix = &pattern[..pattern.len() - 2];
                            mime.starts_with(prefix)
                                && mime.as_bytes().get(prefix.len()) == Some(&b'/')
                        } else {
                            mime == *pattern
                        }
                    });
                if !matched {
                    return Err(ConstraintError::BlobMimeTypeNotAccepted {
                        path: ValidationPath::from_field("artwork"),
                        accepted: vec![
                            "image/png".to_string(), "image/jpeg".to_string()
                        ],
                        actual: mime.to_string(),
                    });
                }
            }
        }
        if let Some(ref value) = self.description {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 10000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("description"),
                    max: 10000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.duration;
            if *value < 1i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("duration"),
                    min: 1i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.episode_number {
            if *value < 1i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("episode_number"),
                    min: 1i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.feed_item_guid;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 2000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("feed_item_guid"),
                    max: 2000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.season_number {
            if *value < 1i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("season_number"),
                    min: 1i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.title;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 500usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("title"),
                    max: 500usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.transcript {
            #[allow(unused_comparisons)]
            if value.len() > 10usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("transcript"),
                    max: 10usize,
                    actual: value.len(),
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for MediaRef<S> {
    fn nsid() -> &'static str {
        "org.atpodcasting.episode"
    }
    fn def_name() -> &'static str {
        "mediaRef"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_org_atpodcasting_episode()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for TranscriptRef<S> {
    fn nsid() -> &'static str {
        "org.atpodcasting.episode"
    }
    fn def_name() -> &'static str {
        "transcriptRef"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_org_atpodcasting_episode()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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

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

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

impl<S: BosStr> ChaptersRef<S> {
    /// Create a new builder for this type
    pub fn builder() -> ChaptersRefBuilder<chapters_ref_state::Empty, S> {
        ChaptersRefBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> ChaptersRefBuilder<St, S>
where
    St: chapters_ref_state::State,
    St::MimeType: chapters_ref_state::IsUnset,
{
    /// Set the `mimeType` field (required)
    pub fn mime_type(
        mut self,
        value: impl Into<S>,
    ) -> ChaptersRefBuilder<chapters_ref_state::SetMimeType<St>, S> {
        self._fields.0 = Option::Some(value.into());
        ChaptersRefBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ChaptersRefBuilder<St, S>
where
    St: chapters_ref_state::State,
    St::Url: chapters_ref_state::IsUnset,
{
    /// Set the `url` field (required)
    pub fn url(
        mut self,
        value: impl Into<UriValue<S>>,
    ) -> ChaptersRefBuilder<chapters_ref_state::SetUrl<St>, S> {
        self._fields.1 = Option::Some(value.into());
        ChaptersRefBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ChaptersRefBuilder<St, S>
where
    St: chapters_ref_state::State,
    St::MimeType: chapters_ref_state::IsSet,
    St::Url: chapters_ref_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ChaptersRef<S> {
        ChaptersRef {
            mime_type: self._fields.0.unwrap(),
            url: 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>>,
    ) -> ChaptersRef<S> {
        ChaptersRef {
            mime_type: self._fields.0.unwrap(),
            url: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_org_atpodcasting_episode() -> 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("org.atpodcasting.episode"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("chaptersRef"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Reference to an externally hosted chapters file.",
                        ),
                    ),
                    required: Some(
                        vec![SmolStr::new_static("url"), SmolStr::new_static("mimeType")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("mimeType"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "MIME type of the chapters file (e.g. application/json+chapters).",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("url"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("URL of the chapters file."),
                                ),
                                format: Some(LexStringFormat::Uri),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "A podcast episode. Record key is a UUIDv5 derived from the podcast GUID (as namespace) and the episode's feedItemGuid (as name), enabling deterministic lookup from RSS feed metadata.",
                        ),
                    ),
                    key: Some(CowStr::new_static("any")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("podcast"),
                                SmolStr::new_static("title"), SmolStr::new_static("media"),
                                SmolStr::new_static("publishedAt"),
                                SmolStr::new_static("duration"),
                                SmolStr::new_static("feedItemGuid"),
                                SmolStr::new_static("createdAt")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("alternateMedia"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "Alternate versions of the episode media (e.g. different formats or audio-only versions of video episodes).",
                                        ),
                                    ),
                                    items: LexArrayItem::Ref(LexRef {
                                        r#ref: CowStr::new_static("#mediaRef"),
                                        ..Default::default()
                                    }),
                                    max_length: Some(10usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("artwork"),
                                LexObjectProperty::Blob(LexBlob { ..Default::default() }),
                            );
                            map.insert(
                                SmolStr::new_static("chapters"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#chaptersRef"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("When the episode record was created."),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("description"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "A description or show notes for the episode.",
                                        ),
                                    ),
                                    max_length: Some(10000usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("duration"),
                                LexObjectProperty::Integer(LexInteger {
                                    minimum: Some(1i64),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("episodeNumber"),
                                LexObjectProperty::Integer(LexInteger {
                                    minimum: Some(1i64),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("episodeType"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("The type of episode. Defaults to full."),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("explicit"),
                                LexObjectProperty::Boolean(LexBoolean {
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("feedItemGuid"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The original feed item identifier. Must match the <guid> element of the corresponding RSS feed item. The record key (rkey) is derived from this value as uuid5(<podcast:guid>, feedItemGuid).",
                                        ),
                                    ),
                                    max_length: Some(2000usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("link"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "URL of a companion webpage or show notes page for the episode.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Uri),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("media"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#mediaRef"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("podcast"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static(
                                        "org.atpodcasting.defs#podcastRef",
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("publishedAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("When the episode was published."),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("seasonNumber"),
                                LexObjectProperty::Integer(LexInteger {
                                    minimum: Some(1i64),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("title"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("The title of the episode."),
                                    ),
                                    max_length: Some(500usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("transcript"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "References to externally hosted transcript files (e.g. VTT, SRT, JSON). Multiple entries allow providing transcripts in different formats.",
                                        ),
                                    ),
                                    items: LexArrayItem::Ref(LexRef {
                                        r#ref: CowStr::new_static("#transcriptRef"),
                                        ..Default::default()
                                    }),
                                    max_length: Some(10usize),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("mediaRef"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Reference to an externally hosted media file.",
                        ),
                    ),
                    required: Some(
                        vec![SmolStr::new_static("url"), SmolStr::new_static("mimeType")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("mimeType"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "MIME type of the media file (e.g. audio/mpeg, video/mp4).",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("url"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("URL of the media file."),
                                ),
                                format: Some(LexStringFormat::Uri),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("transcriptRef"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Reference to an externally hosted transcript file.",
                        ),
                    ),
                    required: Some(
                        vec![SmolStr::new_static("url"), SmolStr::new_static("mimeType")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("language"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Language of the transcript (ISO 639-1 two-letter code, e.g. 'en', 'es', 'pt').",
                                    ),
                                ),
                                format: Some(LexStringFormat::Language),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("mimeType"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "MIME type of the transcript file (e.g. text/vtt, application/x-subrip, application/json).",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("url"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("URL of the transcript file."),
                                ),
                                format: Some(LexStringFormat::Uri),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod episode_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 CreatedAt;
        type Duration;
        type FeedItemGuid;
        type Media;
        type Podcast;
        type PublishedAt;
        type Title;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type CreatedAt = Unset;
        type Duration = Unset;
        type FeedItemGuid = Unset;
        type Media = Unset;
        type Podcast = Unset;
        type PublishedAt = Unset;
        type Title = Unset;
    }
    ///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 CreatedAt = Set<members::created_at>;
        type Duration = St::Duration;
        type FeedItemGuid = St::FeedItemGuid;
        type Media = St::Media;
        type Podcast = St::Podcast;
        type PublishedAt = St::PublishedAt;
        type Title = St::Title;
    }
    ///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 CreatedAt = St::CreatedAt;
        type Duration = Set<members::duration>;
        type FeedItemGuid = St::FeedItemGuid;
        type Media = St::Media;
        type Podcast = St::Podcast;
        type PublishedAt = St::PublishedAt;
        type Title = St::Title;
    }
    ///State transition - sets the `feed_item_guid` field to Set
    pub struct SetFeedItemGuid<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetFeedItemGuid<St> {}
    impl<St: State> State for SetFeedItemGuid<St> {
        type CreatedAt = St::CreatedAt;
        type Duration = St::Duration;
        type FeedItemGuid = Set<members::feed_item_guid>;
        type Media = St::Media;
        type Podcast = St::Podcast;
        type PublishedAt = St::PublishedAt;
        type Title = St::Title;
    }
    ///State transition - sets the `media` field to Set
    pub struct SetMedia<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetMedia<St> {}
    impl<St: State> State for SetMedia<St> {
        type CreatedAt = St::CreatedAt;
        type Duration = St::Duration;
        type FeedItemGuid = St::FeedItemGuid;
        type Media = Set<members::media>;
        type Podcast = St::Podcast;
        type PublishedAt = St::PublishedAt;
        type Title = St::Title;
    }
    ///State transition - sets the `podcast` field to Set
    pub struct SetPodcast<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetPodcast<St> {}
    impl<St: State> State for SetPodcast<St> {
        type CreatedAt = St::CreatedAt;
        type Duration = St::Duration;
        type FeedItemGuid = St::FeedItemGuid;
        type Media = St::Media;
        type Podcast = Set<members::podcast>;
        type PublishedAt = St::PublishedAt;
        type Title = St::Title;
    }
    ///State transition - sets the `published_at` field to Set
    pub struct SetPublishedAt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetPublishedAt<St> {}
    impl<St: State> State for SetPublishedAt<St> {
        type CreatedAt = St::CreatedAt;
        type Duration = St::Duration;
        type FeedItemGuid = St::FeedItemGuid;
        type Media = St::Media;
        type Podcast = St::Podcast;
        type PublishedAt = Set<members::published_at>;
        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 CreatedAt = St::CreatedAt;
        type Duration = St::Duration;
        type FeedItemGuid = St::FeedItemGuid;
        type Media = St::Media;
        type Podcast = St::Podcast;
        type PublishedAt = St::PublishedAt;
        type Title = Set<members::title>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `created_at` field
        pub struct created_at(());
        ///Marker type for the `duration` field
        pub struct duration(());
        ///Marker type for the `feed_item_guid` field
        pub struct feed_item_guid(());
        ///Marker type for the `media` field
        pub struct media(());
        ///Marker type for the `podcast` field
        pub struct podcast(());
        ///Marker type for the `published_at` field
        pub struct published_at(());
        ///Marker type for the `title` field
        pub struct title(());
    }
}

/// Builder for constructing an instance of this type.
pub struct EpisodeBuilder<St: episode_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<Vec<episode::MediaRef<S>>>,
        Option<BlobRef<S>>,
        Option<episode::ChaptersRef<S>>,
        Option<Datetime>,
        Option<S>,
        Option<i64>,
        Option<i64>,
        Option<EpisodeEpisodeType<S>>,
        Option<bool>,
        Option<S>,
        Option<UriValue<S>>,
        Option<episode::MediaRef<S>>,
        Option<PodcastRef<S>>,
        Option<Datetime>,
        Option<i64>,
        Option<S>,
        Option<Vec<episode::TranscriptRef<S>>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Episode<S> {
    /// Create a new builder for this type
    pub fn builder() -> EpisodeBuilder<episode_state::Empty, S> {
        EpisodeBuilder::builder()
    }
}

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

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

impl<St: episode_state::State, S: BosStr> EpisodeBuilder<St, S> {
    /// Set the `alternateMedia` field (optional)
    pub fn alternate_media(
        mut self,
        value: impl Into<Option<Vec<episode::MediaRef<S>>>>,
    ) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `alternateMedia` field to an Option value (optional)
    pub fn maybe_alternate_media(
        mut self,
        value: Option<Vec<episode::MediaRef<S>>>,
    ) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St: episode_state::State, S: BosStr> EpisodeBuilder<St, S> {
    /// Set the `artwork` field (optional)
    pub fn artwork(mut self, value: impl Into<Option<BlobRef<S>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `artwork` field to an Option value (optional)
    pub fn maybe_artwork(mut self, value: Option<BlobRef<S>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St: episode_state::State, S: BosStr> EpisodeBuilder<St, S> {
    /// Set the `chapters` field (optional)
    pub fn chapters(
        mut self,
        value: impl Into<Option<episode::ChaptersRef<S>>>,
    ) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `chapters` field to an Option value (optional)
    pub fn maybe_chapters(mut self, value: Option<episode::ChaptersRef<S>>) -> Self {
        self._fields.2 = value;
        self
    }
}

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

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

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

impl<St: episode_state::State, S: BosStr> EpisodeBuilder<St, S> {
    /// Set the `episodeNumber` field (optional)
    pub fn episode_number(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.6 = value.into();
        self
    }
    /// Set the `episodeNumber` field to an Option value (optional)
    pub fn maybe_episode_number(mut self, value: Option<i64>) -> Self {
        self._fields.6 = value;
        self
    }
}

impl<St: episode_state::State, S: BosStr> EpisodeBuilder<St, S> {
    /// Set the `episodeType` field (optional)
    pub fn episode_type(
        mut self,
        value: impl Into<Option<EpisodeEpisodeType<S>>>,
    ) -> Self {
        self._fields.7 = value.into();
        self
    }
    /// Set the `episodeType` field to an Option value (optional)
    pub fn maybe_episode_type(mut self, value: Option<EpisodeEpisodeType<S>>) -> Self {
        self._fields.7 = value;
        self
    }
}

impl<St: episode_state::State, S: BosStr> EpisodeBuilder<St, S> {
    /// Set the `explicit` field (optional)
    pub fn explicit(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.8 = value.into();
        self
    }
    /// Set the `explicit` field to an Option value (optional)
    pub fn maybe_explicit(mut self, value: Option<bool>) -> Self {
        self._fields.8 = value;
        self
    }
}

impl<St, S: BosStr> EpisodeBuilder<St, S>
where
    St: episode_state::State,
    St::FeedItemGuid: episode_state::IsUnset,
{
    /// Set the `feedItemGuid` field (required)
    pub fn feed_item_guid(
        mut self,
        value: impl Into<S>,
    ) -> EpisodeBuilder<episode_state::SetFeedItemGuid<St>, S> {
        self._fields.9 = Option::Some(value.into());
        EpisodeBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: episode_state::State, S: BosStr> EpisodeBuilder<St, S> {
    /// Set the `link` field (optional)
    pub fn link(mut self, value: impl Into<Option<UriValue<S>>>) -> Self {
        self._fields.10 = value.into();
        self
    }
    /// Set the `link` field to an Option value (optional)
    pub fn maybe_link(mut self, value: Option<UriValue<S>>) -> Self {
        self._fields.10 = value;
        self
    }
}

impl<St, S: BosStr> EpisodeBuilder<St, S>
where
    St: episode_state::State,
    St::Media: episode_state::IsUnset,
{
    /// Set the `media` field (required)
    pub fn media(
        mut self,
        value: impl Into<episode::MediaRef<S>>,
    ) -> EpisodeBuilder<episode_state::SetMedia<St>, S> {
        self._fields.11 = Option::Some(value.into());
        EpisodeBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> EpisodeBuilder<St, S>
where
    St: episode_state::State,
    St::Podcast: episode_state::IsUnset,
{
    /// Set the `podcast` field (required)
    pub fn podcast(
        mut self,
        value: impl Into<PodcastRef<S>>,
    ) -> EpisodeBuilder<episode_state::SetPodcast<St>, S> {
        self._fields.12 = Option::Some(value.into());
        EpisodeBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> EpisodeBuilder<St, S>
where
    St: episode_state::State,
    St::PublishedAt: episode_state::IsUnset,
{
    /// Set the `publishedAt` field (required)
    pub fn published_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> EpisodeBuilder<episode_state::SetPublishedAt<St>, S> {
        self._fields.13 = Option::Some(value.into());
        EpisodeBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: episode_state::State, S: BosStr> EpisodeBuilder<St, S> {
    /// Set the `seasonNumber` field (optional)
    pub fn season_number(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.14 = value.into();
        self
    }
    /// Set the `seasonNumber` field to an Option value (optional)
    pub fn maybe_season_number(mut self, value: Option<i64>) -> Self {
        self._fields.14 = value;
        self
    }
}

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

impl<St: episode_state::State, S: BosStr> EpisodeBuilder<St, S> {
    /// Set the `transcript` field (optional)
    pub fn transcript(
        mut self,
        value: impl Into<Option<Vec<episode::TranscriptRef<S>>>>,
    ) -> Self {
        self._fields.16 = value.into();
        self
    }
    /// Set the `transcript` field to an Option value (optional)
    pub fn maybe_transcript(
        mut self,
        value: Option<Vec<episode::TranscriptRef<S>>>,
    ) -> Self {
        self._fields.16 = value;
        self
    }
}

impl<St, S: BosStr> EpisodeBuilder<St, S>
where
    St: episode_state::State,
    St::CreatedAt: episode_state::IsSet,
    St::Duration: episode_state::IsSet,
    St::FeedItemGuid: episode_state::IsSet,
    St::Media: episode_state::IsSet,
    St::Podcast: episode_state::IsSet,
    St::PublishedAt: episode_state::IsSet,
    St::Title: episode_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Episode<S> {
        Episode {
            alternate_media: self._fields.0,
            artwork: self._fields.1,
            chapters: self._fields.2,
            created_at: self._fields.3.unwrap(),
            description: self._fields.4,
            duration: self._fields.5.unwrap(),
            episode_number: self._fields.6,
            episode_type: self._fields.7,
            explicit: self._fields.8,
            feed_item_guid: self._fields.9.unwrap(),
            link: self._fields.10,
            media: self._fields.11.unwrap(),
            podcast: self._fields.12.unwrap(),
            published_at: self._fields.13.unwrap(),
            season_number: self._fields.14,
            title: self._fields.15.unwrap(),
            transcript: self._fields.16,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Episode<S> {
        Episode {
            alternate_media: self._fields.0,
            artwork: self._fields.1,
            chapters: self._fields.2,
            created_at: self._fields.3.unwrap(),
            description: self._fields.4,
            duration: self._fields.5.unwrap(),
            episode_number: self._fields.6,
            episode_type: self._fields.7,
            explicit: self._fields.8,
            feed_item_guid: self._fields.9.unwrap(),
            link: self._fields.10,
            media: self._fields.11.unwrap(),
            podcast: self._fields.12.unwrap(),
            published_at: self._fields.13.unwrap(),
            season_number: self._fields.14,
            title: self._fields.15.unwrap(),
            transcript: self._fields.16,
            extra_data: Some(extra_data),
        }
    }
}

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

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

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

impl<S: BosStr> MediaRef<S> {
    /// Create a new builder for this type
    pub fn builder() -> MediaRefBuilder<media_ref_state::Empty, S> {
        MediaRefBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> MediaRefBuilder<St, S>
where
    St: media_ref_state::State,
    St::MimeType: media_ref_state::IsUnset,
{
    /// Set the `mimeType` field (required)
    pub fn mime_type(
        mut self,
        value: impl Into<S>,
    ) -> MediaRefBuilder<media_ref_state::SetMimeType<St>, S> {
        self._fields.0 = Option::Some(value.into());
        MediaRefBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> MediaRefBuilder<St, S>
where
    St: media_ref_state::State,
    St::Url: media_ref_state::IsUnset,
{
    /// Set the `url` field (required)
    pub fn url(
        mut self,
        value: impl Into<UriValue<S>>,
    ) -> MediaRefBuilder<media_ref_state::SetUrl<St>, S> {
        self._fields.1 = Option::Some(value.into());
        MediaRefBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> MediaRefBuilder<St, S>
where
    St: media_ref_state::State,
    St::MimeType: media_ref_state::IsSet,
    St::Url: media_ref_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> MediaRef<S> {
        MediaRef {
            mime_type: self._fields.0.unwrap(),
            url: 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>>) -> MediaRef<S> {
        MediaRef {
            mime_type: self._fields.0.unwrap(),
            url: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

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

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

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

impl<S: BosStr> TranscriptRef<S> {
    /// Create a new builder for this type
    pub fn builder() -> TranscriptRefBuilder<transcript_ref_state::Empty, S> {
        TranscriptRefBuilder::builder()
    }
}

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

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

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

impl<St, S: BosStr> TranscriptRefBuilder<St, S>
where
    St: transcript_ref_state::State,
    St::MimeType: transcript_ref_state::IsUnset,
{
    /// Set the `mimeType` field (required)
    pub fn mime_type(
        mut self,
        value: impl Into<S>,
    ) -> TranscriptRefBuilder<transcript_ref_state::SetMimeType<St>, S> {
        self._fields.1 = Option::Some(value.into());
        TranscriptRefBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> TranscriptRefBuilder<St, S>
where
    St: transcript_ref_state::State,
    St::Url: transcript_ref_state::IsUnset,
{
    /// Set the `url` field (required)
    pub fn url(
        mut self,
        value: impl Into<UriValue<S>>,
    ) -> TranscriptRefBuilder<transcript_ref_state::SetUrl<St>, S> {
        self._fields.2 = Option::Some(value.into());
        TranscriptRefBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> TranscriptRefBuilder<St, S>
where
    St: transcript_ref_state::State,
    St::MimeType: transcript_ref_state::IsSet,
    St::Url: transcript_ref_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> TranscriptRef<S> {
        TranscriptRef {
            language: self._fields.0,
            mime_type: self._fields.1.unwrap(),
            url: 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>>,
    ) -> TranscriptRef<S> {
        TranscriptRef {
            language: self._fields.0,
            mime_type: self._fields.1.unwrap(),
            url: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}