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

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
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::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.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ChaptersRef<'a> {
    ///MIME type of the chapters file (e.g. application/json+chapters).
    #[serde(borrow)]
    pub mime_type: CowStr<'a>,
    ///URL of the chapters file.
    #[serde(borrow)]
    pub url: UriValue<'a>,
}

/// 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.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Episode<'a> {
    ///Alternate versions of the episode media (e.g. different formats or audio-only versions of video episodes).
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub alternate_media: Option<Vec<episode::MediaRef<'a>>>,
    ///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")]
    #[serde(borrow)]
    pub artwork: Option<BlobRef<'a>>,
    ///Reference to an externally hosted chapters file.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub chapters: Option<episode::ChaptersRef<'a>>,
    ///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")]
    #[serde(borrow)]
    pub description: Option<CowStr<'a>>,
    ///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")]
    #[serde(borrow)]
    pub episode_type: Option<EpisodeEpisodeType<'a>>,
    ///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).
    #[serde(borrow)]
    pub feed_item_guid: CowStr<'a>,
    ///URL of a companion webpage or show notes page for the episode.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub link: Option<UriValue<'a>>,
    ///The primary media file for the episode.
    #[serde(borrow)]
    pub media: episode::MediaRef<'a>,
    ///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.
    #[serde(borrow)]
    pub podcast: PodcastRef<'a>,
    ///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.
    #[serde(borrow)]
    pub title: CowStr<'a>,
    ///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")]
    #[serde(borrow)]
    pub transcript: Option<Vec<episode::TranscriptRef<'a>>>,
}

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

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum EpisodeEpisodeType<'a> {
    Full,
    Trailer,
    Bonus,
    Other(CowStr<'a>),
}

impl<'a> EpisodeEpisodeType<'a> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Full => "full",
            Self::Trailer => "trailer",
            Self::Bonus => "bonus",
            Self::Other(s) => s.as_ref(),
        }
    }
}

impl<'a> From<&'a str> for EpisodeEpisodeType<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "full" => Self::Full,
            "trailer" => Self::Trailer,
            "bonus" => Self::Bonus,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for EpisodeEpisodeType<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "full" => Self::Full,
            "trailer" => Self::Trailer,
            "bonus" => Self::Bonus,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

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

impl<'a> AsRef<str> for EpisodeEpisodeType<'a> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

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

impl<'de, 'a> serde::Deserialize<'de> for EpisodeEpisodeType<'a>
where
    'de: 'a,
{
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = <&'de str>::deserialize(deserializer)?;
        Ok(Self::from(s))
    }
}

impl<'a> Default for EpisodeEpisodeType<'a> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl jacquard_common::IntoStatic for EpisodeEpisodeType<'_> {
    type Output = EpisodeEpisodeType<'static>;
    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<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cid: Option<Cid<'a>>,
    #[serde(borrow)]
    pub uri: AtUri<'a>,
    #[serde(borrow)]
    pub value: Episode<'a>,
}

/// Reference to an externally hosted media file.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct MediaRef<'a> {
    ///MIME type of the media file (e.g. audio/mpeg, video/mp4).
    #[serde(borrow)]
    pub mime_type: CowStr<'a>,
    ///URL of the media file.
    #[serde(borrow)]
    pub url: UriValue<'a>,
}

/// Reference to an externally hosted transcript file.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct TranscriptRef<'a> {
    ///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).
    #[serde(borrow)]
    pub mime_type: CowStr<'a>,
    ///URL of the transcript file.
    #[serde(borrow)]
    pub url: UriValue<'a>,
}

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

impl<'a> LexiconSchema for ChaptersRef<'a> {
    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<'de> = EpisodeGetRecordOutput<'de>;
    type Err<'de> = RecordError<'de>;
}

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

impl Collection for Episode<'_> {
    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<'a> LexiconSchema for Episode<'a> {
    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<'a> LexiconSchema for MediaRef<'a> {
    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<'a> LexiconSchema for TranscriptRef<'a> {
    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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetMimeType<S> {}
    impl<S: State> State for SetMimeType<S> {
        type MimeType = Set<members::mime_type>;
        type Url = S::Url;
    }
    ///State transition - sets the `url` field to Set
    pub struct SetUrl<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetUrl<S> {}
    impl<S: State> State for SetUrl<S> {
        type MimeType = S::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<'a, S: chapters_ref_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<CowStr<'a>>, Option<UriValue<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

impl<'a, S> ChaptersRefBuilder<'a, S>
where
    S: chapters_ref_state::State,
    S::MimeType: chapters_ref_state::IsSet,
    S::Url: chapters_ref_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> ChaptersRef<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> ChaptersRef<'a> {
        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 Title;
        type PublishedAt;
        type FeedItemGuid;
        type Podcast;
        type Duration;
        type CreatedAt;
        type Media;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Title = Unset;
        type PublishedAt = Unset;
        type FeedItemGuid = Unset;
        type Podcast = Unset;
        type Duration = Unset;
        type CreatedAt = Unset;
        type Media = Unset;
    }
    ///State transition - sets the `title` field to Set
    pub struct SetTitle<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetTitle<S> {}
    impl<S: State> State for SetTitle<S> {
        type Title = Set<members::title>;
        type PublishedAt = S::PublishedAt;
        type FeedItemGuid = S::FeedItemGuid;
        type Podcast = S::Podcast;
        type Duration = S::Duration;
        type CreatedAt = S::CreatedAt;
        type Media = S::Media;
    }
    ///State transition - sets the `published_at` field to Set
    pub struct SetPublishedAt<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetPublishedAt<S> {}
    impl<S: State> State for SetPublishedAt<S> {
        type Title = S::Title;
        type PublishedAt = Set<members::published_at>;
        type FeedItemGuid = S::FeedItemGuid;
        type Podcast = S::Podcast;
        type Duration = S::Duration;
        type CreatedAt = S::CreatedAt;
        type Media = S::Media;
    }
    ///State transition - sets the `feed_item_guid` field to Set
    pub struct SetFeedItemGuid<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetFeedItemGuid<S> {}
    impl<S: State> State for SetFeedItemGuid<S> {
        type Title = S::Title;
        type PublishedAt = S::PublishedAt;
        type FeedItemGuid = Set<members::feed_item_guid>;
        type Podcast = S::Podcast;
        type Duration = S::Duration;
        type CreatedAt = S::CreatedAt;
        type Media = S::Media;
    }
    ///State transition - sets the `podcast` field to Set
    pub struct SetPodcast<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetPodcast<S> {}
    impl<S: State> State for SetPodcast<S> {
        type Title = S::Title;
        type PublishedAt = S::PublishedAt;
        type FeedItemGuid = S::FeedItemGuid;
        type Podcast = Set<members::podcast>;
        type Duration = S::Duration;
        type CreatedAt = S::CreatedAt;
        type Media = S::Media;
    }
    ///State transition - sets the `duration` field to Set
    pub struct SetDuration<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetDuration<S> {}
    impl<S: State> State for SetDuration<S> {
        type Title = S::Title;
        type PublishedAt = S::PublishedAt;
        type FeedItemGuid = S::FeedItemGuid;
        type Podcast = S::Podcast;
        type Duration = Set<members::duration>;
        type CreatedAt = S::CreatedAt;
        type Media = S::Media;
    }
    ///State transition - sets the `created_at` field to Set
    pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
    impl<S: State> State for SetCreatedAt<S> {
        type Title = S::Title;
        type PublishedAt = S::PublishedAt;
        type FeedItemGuid = S::FeedItemGuid;
        type Podcast = S::Podcast;
        type Duration = S::Duration;
        type CreatedAt = Set<members::created_at>;
        type Media = S::Media;
    }
    ///State transition - sets the `media` field to Set
    pub struct SetMedia<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetMedia<S> {}
    impl<S: State> State for SetMedia<S> {
        type Title = S::Title;
        type PublishedAt = S::PublishedAt;
        type FeedItemGuid = S::FeedItemGuid;
        type Podcast = S::Podcast;
        type Duration = S::Duration;
        type CreatedAt = S::CreatedAt;
        type Media = Set<members::media>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `title` field
        pub struct title(());
        ///Marker type for the `published_at` field
        pub struct published_at(());
        ///Marker type for the `feed_item_guid` field
        pub struct feed_item_guid(());
        ///Marker type for the `podcast` field
        pub struct podcast(());
        ///Marker type for the `duration` field
        pub struct duration(());
        ///Marker type for the `created_at` field
        pub struct created_at(());
        ///Marker type for the `media` field
        pub struct media(());
    }
}

/// Builder for constructing an instance of this type
pub struct EpisodeBuilder<'a, S: episode_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<Vec<episode::MediaRef<'a>>>,
        Option<BlobRef<'a>>,
        Option<episode::ChaptersRef<'a>>,
        Option<Datetime>,
        Option<CowStr<'a>>,
        Option<i64>,
        Option<i64>,
        Option<EpisodeEpisodeType<'a>>,
        Option<bool>,
        Option<CowStr<'a>>,
        Option<UriValue<'a>>,
        Option<episode::MediaRef<'a>>,
        Option<PodcastRef<'a>>,
        Option<Datetime>,
        Option<i64>,
        Option<CowStr<'a>>,
        Option<Vec<episode::TranscriptRef<'a>>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

impl<'a> EpisodeBuilder<'a, episode_state::Empty> {
    /// Create a new builder with all fields unset
    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,
            ),
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: episode_state::State> EpisodeBuilder<'a, S> {
    /// Set the `alternateMedia` field (optional)
    pub fn alternate_media(
        mut self,
        value: impl Into<Option<Vec<episode::MediaRef<'a>>>>,
    ) -> 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<'a>>>,
    ) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<'a, S: episode_state::State> EpisodeBuilder<'a, S> {
    /// Set the `artwork` field (optional)
    pub fn artwork(mut self, value: impl Into<Option<BlobRef<'a>>>) -> 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<'a>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<'a, S: episode_state::State> EpisodeBuilder<'a, S> {
    /// Set the `chapters` field (optional)
    pub fn chapters(
        mut self,
        value: impl Into<Option<episode::ChaptersRef<'a>>>,
    ) -> 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<'a>>) -> Self {
        self._fields.2 = value;
        self
    }
}

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

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

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

impl<'a, S: episode_state::State> EpisodeBuilder<'a, 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<'a, S: episode_state::State> EpisodeBuilder<'a, S> {
    /// Set the `episodeType` field (optional)
    pub fn episode_type(
        mut self,
        value: impl Into<Option<EpisodeEpisodeType<'a>>>,
    ) -> 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<'a>>) -> Self {
        self._fields.7 = value;
        self
    }
}

impl<'a, S: episode_state::State> EpisodeBuilder<'a, 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<'a, S> EpisodeBuilder<'a, S>
where
    S: episode_state::State,
    S::FeedItemGuid: episode_state::IsUnset,
{
    /// Set the `feedItemGuid` field (required)
    pub fn feed_item_guid(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> EpisodeBuilder<'a, episode_state::SetFeedItemGuid<S>> {
        self._fields.9 = Option::Some(value.into());
        EpisodeBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: episode_state::State> EpisodeBuilder<'a, S> {
    /// Set the `link` field (optional)
    pub fn link(mut self, value: impl Into<Option<UriValue<'a>>>) -> 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<'a>>) -> Self {
        self._fields.10 = value;
        self
    }
}

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

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

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

impl<'a, S: episode_state::State> EpisodeBuilder<'a, 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<'a, S> EpisodeBuilder<'a, S>
where
    S: episode_state::State,
    S::Title: episode_state::IsUnset,
{
    /// Set the `title` field (required)
    pub fn title(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> EpisodeBuilder<'a, episode_state::SetTitle<S>> {
        self._fields.15 = Option::Some(value.into());
        EpisodeBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: episode_state::State> EpisodeBuilder<'a, S> {
    /// Set the `transcript` field (optional)
    pub fn transcript(
        mut self,
        value: impl Into<Option<Vec<episode::TranscriptRef<'a>>>>,
    ) -> 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<'a>>>,
    ) -> Self {
        self._fields.16 = value;
        self
    }
}

impl<'a, S> EpisodeBuilder<'a, S>
where
    S: episode_state::State,
    S::Title: episode_state::IsSet,
    S::PublishedAt: episode_state::IsSet,
    S::FeedItemGuid: episode_state::IsSet,
    S::Podcast: episode_state::IsSet,
    S::Duration: episode_state::IsSet,
    S::CreatedAt: episode_state::IsSet,
    S::Media: episode_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Episode<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Episode<'a> {
        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 Url;
        type MimeType;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Url = Unset;
        type MimeType = Unset;
    }
    ///State transition - sets the `url` field to Set
    pub struct SetUrl<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetUrl<S> {}
    impl<S: State> State for SetUrl<S> {
        type Url = Set<members::url>;
        type MimeType = S::MimeType;
    }
    ///State transition - sets the `mime_type` field to Set
    pub struct SetMimeType<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetMimeType<S> {}
    impl<S: State> State for SetMimeType<S> {
        type Url = S::Url;
        type MimeType = Set<members::mime_type>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `url` field
        pub struct url(());
        ///Marker type for the `mime_type` field
        pub struct mime_type(());
    }
}

/// Builder for constructing an instance of this type
pub struct MediaRefBuilder<'a, S: media_ref_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<CowStr<'a>>, Option<UriValue<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

impl<'a, S> MediaRefBuilder<'a, S>
where
    S: media_ref_state::State,
    S::Url: media_ref_state::IsSet,
    S::MimeType: media_ref_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> MediaRef<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> MediaRef<'a> {
        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 Url;
        type MimeType;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Url = Unset;
        type MimeType = Unset;
    }
    ///State transition - sets the `url` field to Set
    pub struct SetUrl<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetUrl<S> {}
    impl<S: State> State for SetUrl<S> {
        type Url = Set<members::url>;
        type MimeType = S::MimeType;
    }
    ///State transition - sets the `mime_type` field to Set
    pub struct SetMimeType<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetMimeType<S> {}
    impl<S: State> State for SetMimeType<S> {
        type Url = S::Url;
        type MimeType = Set<members::mime_type>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `url` field
        pub struct url(());
        ///Marker type for the `mime_type` field
        pub struct mime_type(());
    }
}

/// Builder for constructing an instance of this type
pub struct TranscriptRefBuilder<'a, S: transcript_ref_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<Language>, Option<CowStr<'a>>, Option<UriValue<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

impl<'a, S: transcript_ref_state::State> TranscriptRefBuilder<'a, 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<'a, S> TranscriptRefBuilder<'a, S>
where
    S: transcript_ref_state::State,
    S::MimeType: transcript_ref_state::IsUnset,
{
    /// Set the `mimeType` field (required)
    pub fn mime_type(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> TranscriptRefBuilder<'a, transcript_ref_state::SetMimeType<S>> {
        self._fields.1 = Option::Some(value.into());
        TranscriptRefBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

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

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