#[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;
#[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> {
pub looked_up_at: Datetime,
pub results: Vec<lookup::ProviderResult<S>>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
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>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ProviderResult<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub art_url: Option<UriValue<S>>,
pub artist: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub external_id: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub is_album: Option<bool>,
#[serde(default = "_default_provider_result_market_region")]
pub market_region: S,
pub provider: S,
pub title: S,
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)?)
}
}
#[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 {}
}
pub trait State: sealed::Sealed {
type LookedUpAt;
type Results;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type LookedUpAt = Unset;
type Results = Unset;
}
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;
}
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>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct looked_up_at(());
pub struct results(());
}
}
pub struct LookupBuilder<S: BosStr, St: lookup_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<Datetime>, Option<Vec<lookup::ProviderResult<S>>>),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Lookup<S> {
pub fn new() -> LookupBuilder<S, lookup_state::Empty> {
LookupBuilder::new()
}
}
impl<S: BosStr> LookupBuilder<S, lookup_state::Empty> {
pub fn new() -> Self {
LookupBuilder {
_state: PhantomData,
_fields: (None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> LookupBuilder<S, St>
where
St: lookup_state::State,
St::LookedUpAt: lookup_state::IsUnset,
{
pub fn looked_up_at(
mut self,
value: impl Into<Datetime>,
) -> LookupBuilder<S, lookup_state::SetLookedUpAt<St>> {
self._fields.0 = Option::Some(value.into());
LookupBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> LookupBuilder<S, St>
where
St: lookup_state::State,
St::Results: lookup_state::IsUnset,
{
pub fn results(
mut self,
value: impl Into<Vec<lookup::ProviderResult<S>>>,
) -> LookupBuilder<S, lookup_state::SetResults<St>> {
self._fields.1 = Option::Some(value.into());
LookupBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> LookupBuilder<S, St>
where
St: lookup_state::State,
St::LookedUpAt: lookup_state::IsSet,
St::Results: lookup_state::IsSet,
{
pub fn build(self) -> Lookup<S> {
Lookup {
looked_up_at: self._fields.0.unwrap(),
results: self._fields.1.unwrap(),
extra_data: Default::default(),
}
}
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 {}
}
pub trait State: sealed::Sealed {
type Provider;
type MarketRegion;
type Url;
type Artist;
type Title;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Provider = Unset;
type MarketRegion = Unset;
type Url = Unset;
type Artist = Unset;
type Title = Unset;
}
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 Provider = Set<members::provider>;
type MarketRegion = St::MarketRegion;
type Url = St::Url;
type Artist = St::Artist;
type Title = St::Title;
}
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 Provider = St::Provider;
type MarketRegion = Set<members::market_region>;
type Url = St::Url;
type Artist = St::Artist;
type Title = St::Title;
}
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 Provider = St::Provider;
type MarketRegion = St::MarketRegion;
type Url = Set<members::url>;
type Artist = St::Artist;
type Title = St::Title;
}
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 Provider = St::Provider;
type MarketRegion = St::MarketRegion;
type Url = St::Url;
type Artist = Set<members::artist>;
type Title = St::Title;
}
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 Provider = St::Provider;
type MarketRegion = St::MarketRegion;
type Url = St::Url;
type Artist = St::Artist;
type Title = Set<members::title>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct provider(());
pub struct market_region(());
pub struct url(());
pub struct artist(());
pub struct title(());
}
}
pub struct ProviderResultBuilder<S: BosStr, St: provider_result_state::State> {
_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<S: BosStr> ProviderResult<S> {
pub fn new() -> ProviderResultBuilder<S, provider_result_state::Empty> {
ProviderResultBuilder::new()
}
}
impl<S: BosStr> ProviderResultBuilder<S, provider_result_state::Empty> {
pub fn new() -> Self {
ProviderResultBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: provider_result_state::State> ProviderResultBuilder<S, St> {
pub fn art_url(mut self, value: impl Into<Option<UriValue<S>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_art_url(mut self, value: Option<UriValue<S>>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St> ProviderResultBuilder<S, St>
where
St: provider_result_state::State,
St::Artist: provider_result_state::IsUnset,
{
pub fn artist(
mut self,
value: impl Into<S>,
) -> ProviderResultBuilder<S, provider_result_state::SetArtist<St>> {
self._fields.1 = Option::Some(value.into());
ProviderResultBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: provider_result_state::State> ProviderResultBuilder<S, St> {
pub fn external_id(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_external_id(mut self, value: Option<S>) -> Self {
self._fields.2 = value;
self
}
}
impl<S: BosStr, St: provider_result_state::State> ProviderResultBuilder<S, St> {
pub fn is_album(mut self, value: impl Into<Option<bool>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_is_album(mut self, value: Option<bool>) -> Self {
self._fields.3 = value;
self
}
}
impl<S: BosStr, St> ProviderResultBuilder<S, St>
where
St: provider_result_state::State,
St::MarketRegion: provider_result_state::IsUnset,
{
pub fn market_region(
mut self,
value: impl Into<S>,
) -> ProviderResultBuilder<S, provider_result_state::SetMarketRegion<St>> {
self._fields.4 = Option::Some(value.into());
ProviderResultBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ProviderResultBuilder<S, St>
where
St: provider_result_state::State,
St::Provider: provider_result_state::IsUnset,
{
pub fn provider(
mut self,
value: impl Into<S>,
) -> ProviderResultBuilder<S, provider_result_state::SetProvider<St>> {
self._fields.5 = Option::Some(value.into());
ProviderResultBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ProviderResultBuilder<S, St>
where
St: provider_result_state::State,
St::Title: provider_result_state::IsUnset,
{
pub fn title(
mut self,
value: impl Into<S>,
) -> ProviderResultBuilder<S, provider_result_state::SetTitle<St>> {
self._fields.6 = Option::Some(value.into());
ProviderResultBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ProviderResultBuilder<S, St>
where
St: provider_result_state::State,
St::Url: provider_result_state::IsUnset,
{
pub fn url(
mut self,
value: impl Into<UriValue<S>>,
) -> ProviderResultBuilder<S, provider_result_state::SetUrl<St>> {
self._fields.7 = Option::Some(value.into());
ProviderResultBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ProviderResultBuilder<S, St>
where
St: provider_result_state::State,
St::Provider: provider_result_state::IsSet,
St::MarketRegion: provider_result_state::IsSet,
St::Url: provider_result_state::IsSet,
St::Artist: provider_result_state::IsSet,
St::Title: provider_result_state::IsSet,
{
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(),
}
}
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),
}
}
}