// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: fm.teal.alpha.feed.defs
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

pub mod get_actor_feed;
pub mod get_play;
pub mod play;


#[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::string::Datetime;
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::fm_teal::alpha::feed;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct Artist<'a> {
    ///The Musicbrainz ID of the artist
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub artist_mb_id: Option<CowStr<'a>>,
    ///The name of the artist
    #[serde(borrow)]
    pub artist_name: CowStr<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct PlayView<'a> {
    ///Array of artists in order of original appearance.
    #[serde(borrow)]
    pub artists: Vec<feed::Artist<'a>>,
    ///The length of the track in seconds
    #[serde(skip_serializing_if = "Option::is_none")]
    pub duration: Option<i64>,
    ///The ISRC code associated with the recording
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub isrc: Option<CowStr<'a>>,
    ///The base domain of the music service. e.g. music.apple.com, tidal.com, spotify.com. Defaults to 'local' if not provided.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub music_service_base_domain: Option<CowStr<'a>>,
    ///The URL associated with this track
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub origin_url: Option<CowStr<'a>>,
    ///The unix timestamp of when the track was played
    #[serde(skip_serializing_if = "Option::is_none")]
    pub played_time: Option<Datetime>,
    ///The Musicbrainz recording ID of the track
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub recording_mb_id: Option<CowStr<'a>>,
    ///The Musicbrainz release ID
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub release_mb_id: Option<CowStr<'a>>,
    ///The name of the release/album
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub release_name: Option<CowStr<'a>>,
    ///A user-agent style string specifying the user agent. e.g. tealtracker/0.0.1b (Linux; Android 13; SM-A715F). Defaults to 'manual/unknown' if not provided.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub submission_client_agent: Option<CowStr<'a>>,
    ///The Musicbrainz ID of the track
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub track_mb_id: Option<CowStr<'a>>,
    ///The name of the track
    #[serde(borrow)]
    pub track_name: CowStr<'a>,
}

impl<'a> LexiconSchema for Artist<'a> {
    fn nsid() -> &'static str {
        "fm.teal.alpha.feed.defs"
    }
    fn def_name() -> &'static str {
        "artist"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_fm_teal_alpha_feed_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.artist_name;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 256usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("artist_name"),
                    max: 256usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.artist_name;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) < 1usize {
                return Err(ConstraintError::MinLength {
                    path: ValidationPath::from_field("artist_name"),
                    min: 1usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.artist_name;
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 2560usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("artist_name"),
                        max: 2560usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}

impl<'a> LexiconSchema for PlayView<'a> {
    fn nsid() -> &'static str {
        "fm.teal.alpha.feed.defs"
    }
    fn def_name() -> &'static str {
        "playView"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_fm_teal_alpha_feed_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.release_name {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 256usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("release_name"),
                    max: 256usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.release_name {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 2560usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("release_name"),
                        max: 2560usize,
                        actual: count,
                    });
                }
            }
        }
        if let Some(ref value) = self.submission_client_agent {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 256usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("submission_client_agent"),
                    max: 256usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.submission_client_agent {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 2560usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("submission_client_agent"),
                        max: 2560usize,
                        actual: count,
                    });
                }
            }
        }
        {
            let value = &self.track_name;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 256usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("track_name"),
                    max: 256usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.track_name;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) < 1usize {
                return Err(ConstraintError::MinLength {
                    path: ValidationPath::from_field("track_name"),
                    min: 1usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.track_name;
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 2560usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("track_name"),
                        max: 2560usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}

fn lexicon_doc_fm_teal_alpha_feed_defs() -> 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("fm.teal.alpha.feed.defs"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("artist"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("artistName")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("artistMbId"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The Musicbrainz ID of the artist"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("artistName"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The name of the artist"),
                                ),
                                min_length: Some(1usize),
                                max_length: Some(256usize),
                                max_graphemes: Some(2560usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("playView"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("trackName"),
                            SmolStr::new_static("artists")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("artists"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static(
                                        "Array of artists in order of original appearance.",
                                    ),
                                ),
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("#artist"),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("duration"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("isrc"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The ISRC code associated with the recording",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("musicServiceBaseDomain"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The base domain of the music service. e.g. music.apple.com, tidal.com, spotify.com. Defaults to 'local' if not provided.",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("originUrl"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The URL associated with this track"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("playedTime"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The unix timestamp of when the track was played",
                                    ),
                                ),
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("recordingMbId"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The Musicbrainz recording ID of the track",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("releaseMbId"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The Musicbrainz release ID"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("releaseName"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The name of the release/album"),
                                ),
                                max_length: Some(256usize),
                                max_graphemes: Some(2560usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("submissionClientAgent"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "A user-agent style string specifying the user agent. e.g. tealtracker/0.0.1b (Linux; Android 13; SM-A715F). Defaults to 'manual/unknown' if not provided.",
                                    ),
                                ),
                                max_length: Some(256usize),
                                max_graphemes: Some(2560usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("trackMbId"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The Musicbrainz ID of the track"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("trackName"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The name of the track"),
                                ),
                                min_length: Some(1usize),
                                max_length: Some(256usize),
                                max_graphemes: Some(2560usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod play_view_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 Artists;
        type TrackName;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Artists = Unset;
        type TrackName = Unset;
    }
    ///State transition - sets the `artists` field to Set
    pub struct SetArtists<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetArtists<S> {}
    impl<S: State> State for SetArtists<S> {
        type Artists = Set<members::artists>;
        type TrackName = S::TrackName;
    }
    ///State transition - sets the `track_name` field to Set
    pub struct SetTrackName<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetTrackName<S> {}
    impl<S: State> State for SetTrackName<S> {
        type Artists = S::Artists;
        type TrackName = Set<members::track_name>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `artists` field
        pub struct artists(());
        ///Marker type for the `track_name` field
        pub struct track_name(());
    }
}

/// Builder for constructing an instance of this type
pub struct PlayViewBuilder<'a, S: play_view_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<Vec<feed::Artist<'a>>>,
        Option<i64>,
        Option<CowStr<'a>>,
        Option<CowStr<'a>>,
        Option<CowStr<'a>>,
        Option<Datetime>,
        Option<CowStr<'a>>,
        Option<CowStr<'a>>,
        Option<CowStr<'a>>,
        Option<CowStr<'a>>,
        Option<CowStr<'a>>,
        Option<CowStr<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> PlayView<'a> {
    /// Create a new builder for this type
    pub fn new() -> PlayViewBuilder<'a, play_view_state::Empty> {
        PlayViewBuilder::new()
    }
}

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

impl<'a, S> PlayViewBuilder<'a, S>
where
    S: play_view_state::State,
    S::Artists: play_view_state::IsUnset,
{
    /// Set the `artists` field (required)
    pub fn artists(
        mut self,
        value: impl Into<Vec<feed::Artist<'a>>>,
    ) -> PlayViewBuilder<'a, play_view_state::SetArtists<S>> {
        self._fields.0 = Option::Some(value.into());
        PlayViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: play_view_state::State> PlayViewBuilder<'a, S> {
    /// Set the `duration` field (optional)
    pub fn duration(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `duration` field to an Option value (optional)
    pub fn maybe_duration(mut self, value: Option<i64>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<'a, S: play_view_state::State> PlayViewBuilder<'a, S> {
    /// Set the `isrc` field (optional)
    pub fn isrc(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `isrc` field to an Option value (optional)
    pub fn maybe_isrc(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<'a, S: play_view_state::State> PlayViewBuilder<'a, S> {
    /// Set the `musicServiceBaseDomain` field (optional)
    pub fn music_service_base_domain(
        mut self,
        value: impl Into<Option<CowStr<'a>>>,
    ) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `musicServiceBaseDomain` field to an Option value (optional)
    pub fn maybe_music_service_base_domain(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.3 = value;
        self
    }
}

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

impl<'a, S: play_view_state::State> PlayViewBuilder<'a, S> {
    /// Set the `playedTime` field (optional)
    pub fn played_time(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.5 = value.into();
        self
    }
    /// Set the `playedTime` field to an Option value (optional)
    pub fn maybe_played_time(mut self, value: Option<Datetime>) -> Self {
        self._fields.5 = value;
        self
    }
}

impl<'a, S: play_view_state::State> PlayViewBuilder<'a, S> {
    /// Set the `recordingMbId` field (optional)
    pub fn recording_mb_id(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.6 = value.into();
        self
    }
    /// Set the `recordingMbId` field to an Option value (optional)
    pub fn maybe_recording_mb_id(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.6 = value;
        self
    }
}

impl<'a, S: play_view_state::State> PlayViewBuilder<'a, S> {
    /// Set the `releaseMbId` field (optional)
    pub fn release_mb_id(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.7 = value.into();
        self
    }
    /// Set the `releaseMbId` field to an Option value (optional)
    pub fn maybe_release_mb_id(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.7 = value;
        self
    }
}

impl<'a, S: play_view_state::State> PlayViewBuilder<'a, S> {
    /// Set the `releaseName` field (optional)
    pub fn release_name(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.8 = value.into();
        self
    }
    /// Set the `releaseName` field to an Option value (optional)
    pub fn maybe_release_name(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.8 = value;
        self
    }
}

impl<'a, S: play_view_state::State> PlayViewBuilder<'a, S> {
    /// Set the `submissionClientAgent` field (optional)
    pub fn submission_client_agent(
        mut self,
        value: impl Into<Option<CowStr<'a>>>,
    ) -> Self {
        self._fields.9 = value.into();
        self
    }
    /// Set the `submissionClientAgent` field to an Option value (optional)
    pub fn maybe_submission_client_agent(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.9 = value;
        self
    }
}

impl<'a, S: play_view_state::State> PlayViewBuilder<'a, S> {
    /// Set the `trackMbId` field (optional)
    pub fn track_mb_id(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.10 = value.into();
        self
    }
    /// Set the `trackMbId` field to an Option value (optional)
    pub fn maybe_track_mb_id(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.10 = value;
        self
    }
}

impl<'a, S> PlayViewBuilder<'a, S>
where
    S: play_view_state::State,
    S::TrackName: play_view_state::IsUnset,
{
    /// Set the `trackName` field (required)
    pub fn track_name(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> PlayViewBuilder<'a, play_view_state::SetTrackName<S>> {
        self._fields.11 = Option::Some(value.into());
        PlayViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> PlayViewBuilder<'a, S>
where
    S: play_view_state::State,
    S::Artists: play_view_state::IsSet,
    S::TrackName: play_view_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> PlayView<'a> {
        PlayView {
            artists: self._fields.0.unwrap(),
            duration: self._fields.1,
            isrc: self._fields.2,
            music_service_base_domain: self._fields.3,
            origin_url: self._fields.4,
            played_time: self._fields.5,
            recording_mb_id: self._fields.6,
            release_mb_id: self._fields.7,
            release_name: self._fields.8,
            submission_client_agent: self._fields.9,
            track_mb_id: self._fields.10,
            track_name: self._fields.11.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>,
        >,
    ) -> PlayView<'a> {
        PlayView {
            artists: self._fields.0.unwrap(),
            duration: self._fields.1,
            isrc: self._fields.2,
            music_service_base_domain: self._fields.3,
            origin_url: self._fields.4,
            played_time: self._fields.5,
            recording_mb_id: self._fields.6,
            release_mb_id: self._fields.7,
            release_name: self._fields.8,
            submission_client_agent: self._fields.9,
            track_mb_id: self._fields.10,
            track_name: self._fields.11.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}