// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: me.linkna.lastfm
//
// 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};
/// A Last.fm scrobble play record written by Linkname.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Lastfm<'a> {
    ///MusicBrainz ID for the artist.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub artist_mb_id: Option<CowStr<'a>>,
    ///Artist name(s).
    #[serde(borrow)]
    pub artist_names: Vec<CowStr<'a>>,
    ///URL to the album cover art.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cover_art_url: Option<CowStr<'a>>,
    ///When this record was created.
    pub created_at: Datetime,
    ///URL to the track on Last.fm.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub origin_url: Option<UriValue<'a>>,
    ///When the track was played on Last.fm.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub played_time: Option<Datetime>,
    ///MusicBrainz ID for the release/album.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub release_mb_id: Option<CowStr<'a>>,
    ///Album/release name.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub release_name: Option<CowStr<'a>>,
    ///MusicBrainz ID for the track.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub track_mb_id: Option<CowStr<'a>>,
    ///Track/song name.
    #[serde(borrow)]
    pub track_name: CowStr<'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 LastfmGetRecordOutput<'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: Lastfm<'a>,
}

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

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

#[derive(Debug, Serialize, Deserialize)]
pub struct LastfmRecord;
impl XrpcResp for LastfmRecord {
    const NSID: &'static str = "me.linkna.lastfm";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = LastfmGetRecordOutput<'de>;
    type Err<'de> = RecordError<'de>;
}

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

impl Collection for Lastfm<'_> {
    const NSID: &'static str = "me.linkna.lastfm";
    type Record = LastfmRecord;
}

impl Collection for LastfmRecord {
    const NSID: &'static str = "me.linkna.lastfm";
    type Record = LastfmRecord;
}

impl<'a> LexiconSchema for Lastfm<'a> {
    fn nsid() -> &'static str {
        "me.linkna.lastfm"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_me_linkna_lastfm()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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

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

impl<'a> Lastfm<'a> {
    /// Create a new builder for this type
    pub fn new() -> LastfmBuilder<'a, lastfm_state::Empty> {
        LastfmBuilder::new()
    }
}

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

impl<'a, S: lastfm_state::State> LastfmBuilder<'a, S> {
    /// Set the `artistMbId` field (optional)
    pub fn artist_mb_id(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `artistMbId` field to an Option value (optional)
    pub fn maybe_artist_mb_id(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<'a, S> LastfmBuilder<'a, S>
where
    S: lastfm_state::State,
    S::ArtistNames: lastfm_state::IsUnset,
{
    /// Set the `artistNames` field (required)
    pub fn artist_names(
        mut self,
        value: impl Into<Vec<CowStr<'a>>>,
    ) -> LastfmBuilder<'a, lastfm_state::SetArtistNames<S>> {
        self._fields.1 = Option::Some(value.into());
        LastfmBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

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

impl<'a, S> LastfmBuilder<'a, S>
where
    S: lastfm_state::State,
    S::CreatedAt: lastfm_state::IsUnset,
{
    /// Set the `createdAt` field (required)
    pub fn created_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> LastfmBuilder<'a, lastfm_state::SetCreatedAt<S>> {
        self._fields.3 = Option::Some(value.into());
        LastfmBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: lastfm_state::State> LastfmBuilder<'a, S> {
    /// Set the `originUrl` field (optional)
    pub fn origin_url(mut self, value: impl Into<Option<UriValue<'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<UriValue<'a>>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<'a, S: lastfm_state::State> LastfmBuilder<'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: lastfm_state::State> LastfmBuilder<'a, S> {
    /// Set the `releaseMbId` field (optional)
    pub fn release_mb_id(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.6 = 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.6 = value;
        self
    }
}

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

impl<'a, S: lastfm_state::State> LastfmBuilder<'a, S> {
    /// Set the `trackMbId` field (optional)
    pub fn track_mb_id(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.8 = 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.8 = value;
        self
    }
}

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

impl<'a, S> LastfmBuilder<'a, S>
where
    S: lastfm_state::State,
    S::ArtistNames: lastfm_state::IsSet,
    S::TrackName: lastfm_state::IsSet,
    S::CreatedAt: lastfm_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Lastfm<'a> {
        Lastfm {
            artist_mb_id: self._fields.0,
            artist_names: self._fields.1.unwrap(),
            cover_art_url: self._fields.2,
            created_at: self._fields.3.unwrap(),
            origin_url: self._fields.4,
            played_time: self._fields.5,
            release_mb_id: self._fields.6,
            release_name: self._fields.7,
            track_mb_id: self._fields.8,
            track_name: self._fields.9.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>,
        >,
    ) -> Lastfm<'a> {
        Lastfm {
            artist_mb_id: self._fields.0,
            artist_names: self._fields.1.unwrap(),
            cover_art_url: self._fields.2,
            created_at: self._fields.3.unwrap(),
            origin_url: self._fields.4,
            played_time: self._fields.5,
            release_mb_id: self._fields.6,
            release_name: self._fields.7,
            track_mb_id: self._fields.8,
            track_name: self._fields.9.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_me_linkna_lastfm() -> 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("me.linkna.lastfm"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "A Last.fm scrobble play record written by Linkname.",
                        ),
                    ),
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("trackName"),
                                SmolStr::new_static("artistNames"),
                                SmolStr::new_static("createdAt")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("artistMbId"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("MusicBrainz ID for the artist."),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("artistNames"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(CowStr::new_static("Artist name(s).")),
                                    items: LexArrayItem::String(LexString {
                                        ..Default::default()
                                    }),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("coverArtUrl"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("URL to the album cover art."),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("When this record was created."),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("originUrl"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("URL to the track on Last.fm."),
                                    ),
                                    format: Some(LexStringFormat::Uri),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("playedTime"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("When the track was played on Last.fm."),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("releaseMbId"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("MusicBrainz ID for the release/album."),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("releaseName"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Album/release name."),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("trackMbId"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("MusicBrainz ID for the track."),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("trackName"),
                                LexObjectProperty::String(LexString {
                                    description: Some(CowStr::new_static("Track/song name.")),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}