// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: fm.teal.alpha.actor.status
//
// 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};
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};
use crate::fm_teal::alpha::feed::PlayView;
/// This lexicon is in a not officially released state. It is subject to change. | A declaration of the status of the actor. Only one can be shown at a time. If there are multiple, the latest record should be picked and earlier records should be deleted or tombstoned.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Status<'a> {
    ///The unix timestamp of the expiry time of the item. If unavailable, default to 10 minutes past the start time.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub expiry: Option<Datetime>,
    #[serde(borrow)]
    pub item: PlayView<'a>,
    ///The unix timestamp of when the item was recorded
    pub time: Datetime,
}

/// 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 StatusGetRecordOutput<'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: Status<'a>,
}

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

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

#[derive(Debug, Serialize, Deserialize)]
pub struct StatusRecord;
impl XrpcResp for StatusRecord {
    const NSID: &'static str = "fm.teal.alpha.actor.status";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = StatusGetRecordOutput<'de>;
    type Err<'de> = RecordError<'de>;
}

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

impl Collection for Status<'_> {
    const NSID: &'static str = "fm.teal.alpha.actor.status";
    type Record = StatusRecord;
}

impl Collection for StatusRecord {
    const NSID: &'static str = "fm.teal.alpha.actor.status";
    type Record = StatusRecord;
}

impl<'a> LexiconSchema for Status<'a> {
    fn nsid() -> &'static str {
        "fm.teal.alpha.actor.status"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_fm_teal_alpha_actor_status()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

pub mod status_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 Item;
        type Time;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Item = Unset;
        type Time = Unset;
    }
    ///State transition - sets the `item` field to Set
    pub struct SetItem<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetItem<S> {}
    impl<S: State> State for SetItem<S> {
        type Item = Set<members::item>;
        type Time = S::Time;
    }
    ///State transition - sets the `time` field to Set
    pub struct SetTime<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetTime<S> {}
    impl<S: State> State for SetTime<S> {
        type Item = S::Item;
        type Time = Set<members::time>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `item` field
        pub struct item(());
        ///Marker type for the `time` field
        pub struct time(());
    }
}

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

impl<'a> Status<'a> {
    /// Create a new builder for this type
    pub fn new() -> StatusBuilder<'a, status_state::Empty> {
        StatusBuilder::new()
    }
}

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

impl<'a, S: status_state::State> StatusBuilder<'a, S> {
    /// Set the `expiry` field (optional)
    pub fn expiry(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `expiry` field to an Option value (optional)
    pub fn maybe_expiry(mut self, value: Option<Datetime>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<'a, S> StatusBuilder<'a, S>
where
    S: status_state::State,
    S::Item: status_state::IsUnset,
{
    /// Set the `item` field (required)
    pub fn item(
        mut self,
        value: impl Into<PlayView<'a>>,
    ) -> StatusBuilder<'a, status_state::SetItem<S>> {
        self._fields.1 = Option::Some(value.into());
        StatusBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> StatusBuilder<'a, S>
where
    S: status_state::State,
    S::Time: status_state::IsUnset,
{
    /// Set the `time` field (required)
    pub fn time(
        mut self,
        value: impl Into<Datetime>,
    ) -> StatusBuilder<'a, status_state::SetTime<S>> {
        self._fields.2 = Option::Some(value.into());
        StatusBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> StatusBuilder<'a, S>
where
    S: status_state::State,
    S::Item: status_state::IsSet,
    S::Time: status_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Status<'a> {
        Status {
            expiry: self._fields.0,
            item: self._fields.1.unwrap(),
            time: self._fields.2.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>,
        >,
    ) -> Status<'a> {
        Status {
            expiry: self._fields.0,
            item: self._fields.1.unwrap(),
            time: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_fm_teal_alpha_actor_status() -> 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.actor.status"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "This lexicon is in a not officially released state. It is subject to change. | A declaration of the status of the actor. Only one can be shown at a time. If there are multiple, the latest record should be picked and earlier records should be deleted or tombstoned.",
                        ),
                    ),
                    key: Some(CowStr::new_static("literal:self")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("time"), SmolStr::new_static("item")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("expiry"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The unix timestamp of the expiry time of the item. If unavailable, default to 10 minutes past the start time.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("item"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static(
                                        "fm.teal.alpha.feed.defs#playView",
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("time"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The unix timestamp of when the item was recorded",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}