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

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

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Lookup<'a> {
    ///ISO8601 timestamp of when this lookup was performed.
    pub looked_up_at: Datetime,
    ///Collection of lookup results from each provider that returned a match.
    #[serde(borrow)]
    pub results: Vec<lookup::ProviderResult<'a>>,
}

/// Typed wrapper for GetRecord response with this collection's record type.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct LookupGetRecordOutput<'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: Lookup<'a>,
}

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

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ProviderResult<'a> {
    ///URL to the cover artwork image.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub art_url: Option<UriValue<'a>>,
    ///Primary artist name for the track or album artist.
    #[serde(borrow)]
    pub artist: CowStr<'a>,
    ///ISRC (for tracks) or UPC (for albums) identifier for cross-platform matching.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub external_id: Option<CowStr<'a>>,
    ///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")]
    #[serde(borrow)]
    pub market_region: CowStr<'a>,
    ///The streaming platform provider.
    #[serde(borrow)]
    pub provider: CowStr<'a>,
    ///Official title of the track or album as listed in the provider's catalog.
    #[serde(borrow)]
    pub title: CowStr<'a>,
    ///Direct web link to the track or album on the provider's platform.
    #[serde(borrow)]
    pub url: UriValue<'a>,
}

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

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

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

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

/// Builder for constructing an instance of this type
pub struct LookupBuilder<'a, S: lookup_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<Datetime>, Option<Vec<lookup::ProviderResult<'a>>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

impl<'a, S> LookupBuilder<'a, S>
where
    S: lookup_state::State,
    S::Results: lookup_state::IsSet,
    S::LookedUpAt: lookup_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Lookup<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Lookup<'a> {
        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() -> CowStr<'static> {
    CowStr::from("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 Url;
        type Title;
        type Provider;
    }
    /// 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 Url = Unset;
        type Title = Unset;
        type Provider = Unset;
    }
    ///State transition - sets the `artist` field to Set
    pub struct SetArtist<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetArtist<S> {}
    impl<S: State> State for SetArtist<S> {
        type Artist = Set<members::artist>;
        type MarketRegion = S::MarketRegion;
        type Url = S::Url;
        type Title = S::Title;
        type Provider = S::Provider;
    }
    ///State transition - sets the `market_region` field to Set
    pub struct SetMarketRegion<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetMarketRegion<S> {}
    impl<S: State> State for SetMarketRegion<S> {
        type Artist = S::Artist;
        type MarketRegion = Set<members::market_region>;
        type Url = S::Url;
        type Title = S::Title;
        type Provider = S::Provider;
    }
    ///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 Artist = S::Artist;
        type MarketRegion = S::MarketRegion;
        type Url = Set<members::url>;
        type Title = S::Title;
        type Provider = S::Provider;
    }
    ///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 Artist = S::Artist;
        type MarketRegion = S::MarketRegion;
        type Url = S::Url;
        type Title = Set<members::title>;
        type Provider = S::Provider;
    }
    ///State transition - sets the `provider` field to Set
    pub struct SetProvider<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetProvider<S> {}
    impl<S: State> State for SetProvider<S> {
        type Artist = S::Artist;
        type MarketRegion = S::MarketRegion;
        type Url = S::Url;
        type Title = S::Title;
        type Provider = Set<members::provider>;
    }
    /// 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 `url` field
        pub struct url(());
        ///Marker type for the `title` field
        pub struct title(());
        ///Marker type for the `provider` field
        pub struct provider(());
    }
}

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

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

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

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

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

impl<'a, S: provider_result_state::State> ProviderResultBuilder<'a, S> {
    /// Set the `externalId` field (optional)
    pub fn external_id(mut self, value: impl Into<Option<CowStr<'a>>>) -> 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<CowStr<'a>>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<'a, S: provider_result_state::State> ProviderResultBuilder<'a, 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<'a, S> ProviderResultBuilder<'a, S>
where
    S: provider_result_state::State,
    S::MarketRegion: provider_result_state::IsUnset,
{
    /// Set the `marketRegion` field (required)
    pub fn market_region(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> ProviderResultBuilder<'a, provider_result_state::SetMarketRegion<S>> {
        self._fields.4 = Option::Some(value.into());
        ProviderResultBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

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

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

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

impl<'a, S> ProviderResultBuilder<'a, S>
where
    S: provider_result_state::State,
    S::Artist: provider_result_state::IsSet,
    S::MarketRegion: provider_result_state::IsSet,
    S::Url: provider_result_state::IsSet,
    S::Title: provider_result_state::IsSet,
    S::Provider: provider_result_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> ProviderResult<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> ProviderResult<'a> {
        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),
        }
    }
}