#[allow(unused_imports)]
use alloc::collections::BTreeMap;
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::string::UriValue;
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;
#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Credit<S: BosStr = DefaultStr> {
pub name: S,
pub role: CreditRole<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub url: Option<UriValue<S>>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum CreditRole<S: BosStr = DefaultStr> {
Composer,
Arranger,
Lyricist,
Transcriber,
Orchestrator,
Adapter,
Artist,
Producer,
Other(S),
}
impl<S: BosStr> CreditRole<S> {
pub fn as_str(&self) -> &str {
match self {
Self::Composer => "composer",
Self::Arranger => "arranger",
Self::Lyricist => "lyricist",
Self::Transcriber => "transcriber",
Self::Orchestrator => "orchestrator",
Self::Adapter => "adapter",
Self::Artist => "artist",
Self::Producer => "producer",
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"composer" => Self::Composer,
"arranger" => Self::Arranger,
"lyricist" => Self::Lyricist,
"transcriber" => Self::Transcriber,
"orchestrator" => Self::Orchestrator,
"adapter" => Self::Adapter,
"artist" => Self::Artist,
"producer" => Self::Producer,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> core::fmt::Display for CreditRole<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for CreditRole<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for CreditRole<S> {
fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where
Ser: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for CreditRole<S> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = S::deserialize(deserializer)?;
Ok(Self::from_value(s))
}
}
impl<S: BosStr + Default> Default for CreditRole<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for CreditRole<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = CreditRole<S::Output>;
fn into_static(self) -> Self::Output {
match self {
CreditRole::Composer => CreditRole::Composer,
CreditRole::Arranger => CreditRole::Arranger,
CreditRole::Lyricist => CreditRole::Lyricist,
CreditRole::Transcriber => CreditRole::Transcriber,
CreditRole::Orchestrator => CreditRole::Orchestrator,
CreditRole::Adapter => CreditRole::Adapter,
CreditRole::Artist => CreditRole::Artist,
CreditRole::Producer => CreditRole::Producer,
CreditRole::Other(v) => CreditRole::Other(v.into_static()),
}
}
}
impl<S: BosStr> LexiconSchema for Credit<S> {
fn nsid() -> &'static str {
"io.sound.credit"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_io_sound_credit()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.name;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 640usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("name"),
max: 640usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.name;
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 320usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("name"),
max: 320usize,
actual: count,
});
}
}
}
{
let value = &self.role;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 64usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("role"),
max: 64usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.role;
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 32usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("role"),
max: 32usize,
actual: count,
});
}
}
}
Ok(())
}
}
fn lexicon_doc_io_sound_credit() -> 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("io.sound.credit"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Object(LexObject {
description: Some(
CowStr::new_static("Attribution for a creative work"),
),
required: Some(
vec![SmolStr::new_static("name"), SmolStr::new_static("role")],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("name"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Name of the credited person"),
),
max_length: Some(640usize),
max_graphemes: Some(320usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("role"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Role: composer, lyricist, arranger, etc",
),
),
max_length: Some(64usize),
max_graphemes: Some(32usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("url"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"URL to credited person's profile or website",
),
),
format: Some(LexStringFormat::Uri),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}