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

#[allow(unused_imports)]
use alloc::collections::BTreeMap;

#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{CowStr, BosStr, DefaultStr, FromStaticStr};

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime, 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::link_bridgebeats::lookup;
/// Result of parsing and looking up media links across supported music streaming providers.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "link.bridgebeats.lookup",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Lookup<S: BosStr = DefaultStr> {
    ///ISO8601 timestamp of when this lookup was performed.
    pub looked_up_at: Datetime,
    ///Collection of lookup results from each provider that returned a match.
    pub results: Vec<lookup::ProviderResult<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

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

/// Music metadata from a specific provider's API query.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ProviderResult<S: BosStr = DefaultStr> {
    ///URL to the cover artwork image.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub art_url: Option<UriValue<S>>,
    ///Primary artist name for the track or album artist.
    pub artist: S,
    ///ISRC (for tracks) or UPC (for albums) identifier for cross-platform matching.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub external_id: Option<S>,
    ///True for albums/EPs, false for individual tracks.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_album: Option<bool>,
    ///ISO3166-1 alpha-2 country code for the market/storefront.  Defaults to `"us"`.
    #[serde(default = "_default_provider_result_market_region")]
    pub market_region: S,
    ///The streaming platform provider.
    pub provider: S,
    ///Official title of the track or album as listed in the provider's catalog.
    pub title: S,
    ///Direct web link to the track or album on the provider's platform.
    pub url: UriValue<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

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

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

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

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

impl<S: BosStr> Collection for Lookup<S> {
    const NSID: &'static str = "link.bridgebeats.lookup";
    type Record = LookupRecord;
}

impl Collection for LookupRecord {
    const NSID: &'static str = "link.bridgebeats.lookup";
    type Record = LookupRecord;
}

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

impl<S: BosStr> LexiconSchema for ProviderResult<S> {
    fn nsid() -> &'static str {
        "link.bridgebeats.lookup"
    }
    fn def_name() -> &'static str {
        "providerResult"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_link_bridgebeats_lookup()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.art_url {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 2000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("art_url"),
                    max: 2000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.artist;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 500usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("artist"),
                    max: 500usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.external_id {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 50usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("external_id"),
                    max: 50usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.market_region;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 2usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("market_region"),
                    max: 2usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            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()),
                });
            }
        }
        {
            let value = &self.url;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 2000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("url"),
                    max: 2000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

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

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

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

impl<S: BosStr> Lookup<S> {
    /// Create a new builder for this type
    pub fn builder() -> LookupBuilder<lookup_state::Empty, S> {
        LookupBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> LookupBuilder<St, S>
where
    St: lookup_state::State,
    St::LookedUpAt: lookup_state::IsUnset,
{
    /// Set the `lookedUpAt` field (required)
    pub fn looked_up_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> LookupBuilder<lookup_state::SetLookedUpAt<St>, S> {
        self._fields.0 = Option::Some(value.into());
        LookupBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> LookupBuilder<St, S>
where
    St: lookup_state::State,
    St::Results: lookup_state::IsUnset,
{
    /// Set the `results` field (required)
    pub fn results(
        mut self,
        value: impl Into<Vec<lookup::ProviderResult<S>>>,
    ) -> LookupBuilder<lookup_state::SetResults<St>, S> {
        self._fields.1 = Option::Some(value.into());
        LookupBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> LookupBuilder<St, S>
where
    St: lookup_state::State,
    St::LookedUpAt: lookup_state::IsSet,
    St::Results: lookup_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Lookup<S> {
        Lookup {
            looked_up_at: self._fields.0.unwrap(),
            results: 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>>) -> Lookup<S> {
        Lookup {
            looked_up_at: self._fields.0.unwrap(),
            results: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_link_bridgebeats_lookup() -> 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("link.bridgebeats.lookup"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "Result of parsing and looking up media links across supported music streaming providers.",
                        ),
                    ),
                    key: Some(CowStr::new_static("any")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("results"),
                                SmolStr::new_static("lookedUpAt")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("lookedUpAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "ISO8601 timestamp of when this lookup was performed.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("results"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "Collection of lookup results from each provider that returned a match.",
                                        ),
                                    ),
                                    items: LexArrayItem::Ref(LexRef {
                                        r#ref: CowStr::new_static("#providerResult"),
                                        ..Default::default()
                                    }),
                                    min_length: Some(1usize),
                                    max_length: Some(10usize),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("providerResult"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Music metadata from a specific provider's API query.",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("provider"),
                            SmolStr::new_static("artist"), SmolStr::new_static("title"),
                            SmolStr::new_static("url"),
                            SmolStr::new_static("marketRegion")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("artUrl"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("URL to the cover artwork image."),
                                ),
                                format: Some(LexStringFormat::Uri),
                                max_length: Some(2000usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("artist"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Primary artist name for the track or album artist.",
                                    ),
                                ),
                                max_length: Some(500usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("externalId"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "ISRC (for tracks) or UPC (for albums) identifier for cross-platform matching.",
                                    ),
                                ),
                                max_length: Some(50usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("isAlbum"),
                            LexObjectProperty::Boolean(LexBoolean {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("marketRegion"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "ISO3166-1 alpha-2 country code for the market/storefront.",
                                    ),
                                ),
                                max_length: Some(2usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("provider"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The streaming platform provider."),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("title"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Official title of the track or album as listed in the provider's catalog.",
                                    ),
                                ),
                                max_length: Some(500usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("url"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Direct web link to the track or album on the provider's platform.",
                                    ),
                                ),
                                format: Some(LexStringFormat::Uri),
                                max_length: Some(2000usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

fn _default_provider_result_market_region<S: FromStaticStr>() -> S {
    S::from_static("us")
}

pub mod provider_result_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 Artist;
        type MarketRegion;
        type Provider;
        type Title;
        type Url;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Artist = Unset;
        type MarketRegion = Unset;
        type Provider = Unset;
        type Title = Unset;
        type Url = Unset;
    }
    ///State transition - sets the `artist` field to Set
    pub struct SetArtist<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetArtist<St> {}
    impl<St: State> State for SetArtist<St> {
        type Artist = Set<members::artist>;
        type MarketRegion = St::MarketRegion;
        type Provider = St::Provider;
        type Title = St::Title;
        type Url = St::Url;
    }
    ///State transition - sets the `market_region` field to Set
    pub struct SetMarketRegion<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetMarketRegion<St> {}
    impl<St: State> State for SetMarketRegion<St> {
        type Artist = St::Artist;
        type MarketRegion = Set<members::market_region>;
        type Provider = St::Provider;
        type Title = St::Title;
        type Url = St::Url;
    }
    ///State transition - sets the `provider` field to Set
    pub struct SetProvider<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetProvider<St> {}
    impl<St: State> State for SetProvider<St> {
        type Artist = St::Artist;
        type MarketRegion = St::MarketRegion;
        type Provider = Set<members::provider>;
        type Title = St::Title;
        type Url = St::Url;
    }
    ///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 Artist = St::Artist;
        type MarketRegion = St::MarketRegion;
        type Provider = St::Provider;
        type Title = Set<members::title>;
        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 Artist = St::Artist;
        type MarketRegion = St::MarketRegion;
        type Provider = St::Provider;
        type Title = St::Title;
        type Url = Set<members::url>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `artist` field
        pub struct artist(());
        ///Marker type for the `market_region` field
        pub struct market_region(());
        ///Marker type for the `provider` field
        pub struct provider(());
        ///Marker type for the `title` field
        pub struct title(());
        ///Marker type for the `url` field
        pub struct url(());
    }
}

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

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

impl<S: BosStr> ProviderResult<S> {
    /// Create a new builder for this type
    pub fn builder() -> ProviderResultBuilder<provider_result_state::Empty, S> {
        ProviderResultBuilder::builder()
    }
}

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

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

impl<St: provider_result_state::State, S: BosStr> ProviderResultBuilder<St, S> {
    /// Set the `artUrl` field (optional)
    pub fn art_url(mut self, value: impl Into<Option<UriValue<S>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `artUrl` field to an Option value (optional)
    pub fn maybe_art_url(mut self, value: Option<UriValue<S>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St, S: BosStr> ProviderResultBuilder<St, S>
where
    St: provider_result_state::State,
    St::Artist: provider_result_state::IsUnset,
{
    /// Set the `artist` field (required)
    pub fn artist(
        mut self,
        value: impl Into<S>,
    ) -> ProviderResultBuilder<provider_result_state::SetArtist<St>, S> {
        self._fields.1 = Option::Some(value.into());
        ProviderResultBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: provider_result_state::State, S: BosStr> ProviderResultBuilder<St, S> {
    /// Set the `externalId` field (optional)
    pub fn external_id(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `externalId` field to an Option value (optional)
    pub fn maybe_external_id(mut self, value: Option<S>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<St: provider_result_state::State, S: BosStr> ProviderResultBuilder<St, S> {
    /// Set the `isAlbum` field (optional)
    pub fn is_album(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `isAlbum` field to an Option value (optional)
    pub fn maybe_is_album(mut self, value: Option<bool>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<St, S: BosStr> ProviderResultBuilder<St, S>
where
    St: provider_result_state::State,
    St::MarketRegion: provider_result_state::IsUnset,
{
    /// Set the `marketRegion` field (required)
    pub fn market_region(
        mut self,
        value: impl Into<S>,
    ) -> ProviderResultBuilder<provider_result_state::SetMarketRegion<St>, S> {
        self._fields.4 = Option::Some(value.into());
        ProviderResultBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ProviderResultBuilder<St, S>
where
    St: provider_result_state::State,
    St::Provider: provider_result_state::IsUnset,
{
    /// Set the `provider` field (required)
    pub fn provider(
        mut self,
        value: impl Into<S>,
    ) -> ProviderResultBuilder<provider_result_state::SetProvider<St>, S> {
        self._fields.5 = Option::Some(value.into());
        ProviderResultBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

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

impl<St, S: BosStr> ProviderResultBuilder<St, S>
where
    St: provider_result_state::State,
    St::Artist: provider_result_state::IsSet,
    St::MarketRegion: provider_result_state::IsSet,
    St::Provider: provider_result_state::IsSet,
    St::Title: provider_result_state::IsSet,
    St::Url: provider_result_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ProviderResult<S> {
        ProviderResult {
            art_url: self._fields.0,
            artist: self._fields.1.unwrap(),
            external_id: self._fields.2,
            is_album: self._fields.3,
            market_region: self._fields.4.unwrap(),
            provider: self._fields.5.unwrap(),
            title: self._fields.6.unwrap(),
            url: self._fields.7.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>>,
    ) -> ProviderResult<S> {
        ProviderResult {
            art_url: self._fields.0,
            artist: self._fields.1.unwrap(),
            external_id: self._fields.2,
            is_album: self._fields.3,
            market_region: self._fields.4.unwrap(),
            provider: self._fields.5.unwrap(),
            title: self._fields.6.unwrap(),
            url: self._fields.7.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}