// @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, 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};
/// A Last.fm scrobble play record written by Linkname.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "me.linkna.lastfm",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Lastfm<S: BosStr = DefaultStr> {
    ///MusicBrainz ID for the artist.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub artist_mb_id: Option<S>,
    ///Artist name(s).
    pub artist_names: Vec<S>,
    ///URL to the album cover art.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cover_art_url: Option<S>,
    ///When this record was created.
    pub created_at: Datetime,
    ///URL to the track on Last.fm.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub origin_url: Option<UriValue<S>>,
    ///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")]
    pub release_mb_id: Option<S>,
    ///Album/release name.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub release_name: Option<S>,
    ///MusicBrainz ID for the track.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub track_mb_id: Option<S>,
    ///Track/song name.
    pub track_name: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// 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<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: Lastfm<S>,
}

impl<S: BosStr> Lastfm<S> {
    pub fn uri(uri: S) -> Result<RecordUri<S, LastfmRecord>, UriError> {
        RecordUri::try_from_uri(AtUri::new(uri)?)
    }
}

/// 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<S: BosStr> = LastfmGetRecordOutput<S>;
    type Err = RecordError;
}

impl<S: BosStr> From<LastfmGetRecordOutput<S>> for Lastfm<S> {
    fn from(output: LastfmGetRecordOutput<S>) -> Self {
        output.value
    }
}

impl<S: BosStr> Collection for Lastfm<S> {
    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<S: BosStr> LexiconSchema for Lastfm<S> {
    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 CreatedAt;
        type TrackName;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type ArtistNames = Unset;
        type CreatedAt = Unset;
        type TrackName = Unset;
    }
    ///State transition - sets the `artist_names` field to Set
    pub struct SetArtistNames<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetArtistNames<St> {}
    impl<St: State> State for SetArtistNames<St> {
        type ArtistNames = Set<members::artist_names>;
        type CreatedAt = St::CreatedAt;
        type TrackName = St::TrackName;
    }
    ///State transition - sets the `created_at` field to Set
    pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
    impl<St: State> State for SetCreatedAt<St> {
        type ArtistNames = St::ArtistNames;
        type CreatedAt = Set<members::created_at>;
        type TrackName = St::TrackName;
    }
    ///State transition - sets the `track_name` field to Set
    pub struct SetTrackName<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetTrackName<St> {}
    impl<St: State> State for SetTrackName<St> {
        type ArtistNames = St::ArtistNames;
        type CreatedAt = St::CreatedAt;
        type TrackName = Set<members::track_name>;
    }
    /// 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 `created_at` field
        pub struct created_at(());
        ///Marker type for the `track_name` field
        pub struct track_name(());
    }
}

/// Builder for constructing an instance of this type.
pub struct LastfmBuilder<St: lastfm_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<S>,
        Option<Vec<S>>,
        Option<S>,
        Option<Datetime>,
        Option<UriValue<S>>,
        Option<Datetime>,
        Option<S>,
        Option<S>,
        Option<S>,
        Option<S>,
    ),
    _type: PhantomData<fn() -> S>,
}

impl Lastfm<DefaultStr> {
    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
    pub fn new() -> LastfmBuilder<lastfm_state::Empty, DefaultStr> {
        LastfmBuilder::new()
    }
}

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

impl LastfmBuilder<lastfm_state::Empty, DefaultStr> {
    /// Create a new builder with all fields unset, using the default string type, if needed
    pub fn new() -> Self {
        LastfmBuilder {
            _state: PhantomData,
            _fields: (None, None, None, None, None, None, None, None, None, None),
            _type: PhantomData,
        }
    }
}

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

impl<St: lastfm_state::State, S: BosStr> LastfmBuilder<St, S> {
    /// Set the `artistMbId` field (optional)
    pub fn artist_mb_id(mut self, value: impl Into<Option<S>>) -> 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<S>) -> Self {
        self._fields.0 = value;
        self
    }
}

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

impl<St: lastfm_state::State, S: BosStr> LastfmBuilder<St, S> {
    /// Set the `coverArtUrl` field (optional)
    pub fn cover_art_url(mut self, value: impl Into<Option<S>>) -> 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<S>) -> Self {
        self._fields.2 = value;
        self
    }
}

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

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

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

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

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

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

impl<St, S: BosStr> LastfmBuilder<St, S>
where
    St: lastfm_state::State,
    St::ArtistNames: lastfm_state::IsSet,
    St::CreatedAt: lastfm_state::IsSet,
    St::TrackName: lastfm_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Lastfm<S> {
        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<SmolStr, Data<S>>) -> Lastfm<S> {
        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()
    }
}