// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: sh.weaver.embed.recordWithMedia
//
// 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;

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_derive::{IntoStatic, lexicon, open_union};
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::sh_weaver::embed::external::External;
use crate::sh_weaver::embed::images::Images;
use crate::sh_weaver::embed::records::Records;
use crate::sh_weaver::embed::video::VideoRecord;
use crate::sh_weaver::embed::external;
use crate::sh_weaver::embed::images;
use crate::sh_weaver::embed::records;
use crate::sh_weaver::embed::video;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct RecordWithMedia<'a> {
    #[serde(borrow)]
    pub media: RecordWithMediaMedia<'a>,
    #[serde(borrow)]
    pub records: Records<'a>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum RecordWithMediaMedia<'a> {
    #[serde(rename = "sh.weaver.embed.images")]
    Images(Box<Images<'a>>),
    #[serde(rename = "sh.weaver.embed.external")]
    External(Box<External<'a>>),
    #[serde(rename = "sh.weaver.embed.video")]
    Video(Box<VideoRecord<'a>>),
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct View<'a> {
    #[serde(borrow)]
    pub media: ViewMedia<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub records: Option<records::View<'a>>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum ViewMedia<'a> {
    #[serde(rename = "sh.weaver.embed.images#view")]
    ImagesView(Box<images::View<'a>>),
    #[serde(rename = "sh.weaver.embed.external#view")]
    ExternalView(Box<external::View<'a>>),
    #[serde(rename = "sh.weaver.embed.video#view")]
    VideoView(Box<video::View<'a>>),
}

impl<'a> LexiconSchema for RecordWithMedia<'a> {
    fn nsid() -> &'static str {
        "sh.weaver.embed.recordWithMedia"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_weaver_embed_recordWithMedia()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for View<'a> {
    fn nsid() -> &'static str {
        "sh.weaver.embed.recordWithMedia"
    }
    fn def_name() -> &'static str {
        "view"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_weaver_embed_recordWithMedia()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

pub mod record_with_media_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 Media;
        type Records;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Media = Unset;
        type Records = Unset;
    }
    ///State transition - sets the `media` field to Set
    pub struct SetMedia<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetMedia<S> {}
    impl<S: State> State for SetMedia<S> {
        type Media = Set<members::media>;
        type Records = S::Records;
    }
    ///State transition - sets the `records` field to Set
    pub struct SetRecords<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetRecords<S> {}
    impl<S: State> State for SetRecords<S> {
        type Media = S::Media;
        type Records = Set<members::records>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `media` field
        pub struct media(());
        ///Marker type for the `records` field
        pub struct records(());
    }
}

/// Builder for constructing an instance of this type
pub struct RecordWithMediaBuilder<'a, S: record_with_media_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<RecordWithMediaMedia<'a>>, Option<Records<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> RecordWithMedia<'a> {
    /// Create a new builder for this type
    pub fn new() -> RecordWithMediaBuilder<'a, record_with_media_state::Empty> {
        RecordWithMediaBuilder::new()
    }
}

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

impl<'a, S> RecordWithMediaBuilder<'a, S>
where
    S: record_with_media_state::State,
    S::Media: record_with_media_state::IsUnset,
{
    /// Set the `media` field (required)
    pub fn media(
        mut self,
        value: impl Into<RecordWithMediaMedia<'a>>,
    ) -> RecordWithMediaBuilder<'a, record_with_media_state::SetMedia<S>> {
        self._fields.0 = Option::Some(value.into());
        RecordWithMediaBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> RecordWithMediaBuilder<'a, S>
where
    S: record_with_media_state::State,
    S::Records: record_with_media_state::IsUnset,
{
    /// Set the `records` field (required)
    pub fn records(
        mut self,
        value: impl Into<Records<'a>>,
    ) -> RecordWithMediaBuilder<'a, record_with_media_state::SetRecords<S>> {
        self._fields.1 = Option::Some(value.into());
        RecordWithMediaBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> RecordWithMediaBuilder<'a, S>
where
    S: record_with_media_state::State,
    S::Media: record_with_media_state::IsSet,
    S::Records: record_with_media_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> RecordWithMedia<'a> {
        RecordWithMedia {
            media: self._fields.0.unwrap(),
            records: self._fields.1.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>,
        >,
    ) -> RecordWithMedia<'a> {
        RecordWithMedia {
            media: self._fields.0.unwrap(),
            records: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_sh_weaver_embed_recordWithMedia() -> 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("sh.weaver.embed.recordWithMedia"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("records"), SmolStr::new_static("media")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("media"),
                            LexObjectProperty::Union(LexRefUnion {
                                refs: vec![
                                    CowStr::new_static("sh.weaver.embed.images"),
                                    CowStr::new_static("sh.weaver.embed.external"),
                                    CowStr::new_static("sh.weaver.embed.video")
                                ],
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("records"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("sh.weaver.embed.records"),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("view"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("record"), SmolStr::new_static("media")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("media"),
                            LexObjectProperty::Union(LexRefUnion {
                                refs: vec![
                                    CowStr::new_static("sh.weaver.embed.images#view"),
                                    CowStr::new_static("sh.weaver.embed.external#view"),
                                    CowStr::new_static("sh.weaver.embed.video#view")
                                ],
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("records"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("sh.weaver.embed.records#view"),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

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

/// Builder for constructing an instance of this type
pub struct ViewBuilder<'a, S: view_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<ViewMedia<'a>>, Option<records::View<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> View<'a> {
    /// Create a new builder for this type
    pub fn new() -> ViewBuilder<'a, view_state::Empty> {
        ViewBuilder::new()
    }
}

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

impl<'a, S> ViewBuilder<'a, S>
where
    S: view_state::State,
    S::Media: view_state::IsUnset,
{
    /// Set the `media` field (required)
    pub fn media(
        mut self,
        value: impl Into<ViewMedia<'a>>,
    ) -> ViewBuilder<'a, view_state::SetMedia<S>> {
        self._fields.0 = Option::Some(value.into());
        ViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: view_state::State> ViewBuilder<'a, S> {
    /// Set the `records` field (optional)
    pub fn records(mut self, value: impl Into<Option<records::View<'a>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `records` field to an Option value (optional)
    pub fn maybe_records(mut self, value: Option<records::View<'a>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<'a, S> ViewBuilder<'a, S>
where
    S: view_state::State,
    S::Record: view_state::IsSet,
    S::Media: view_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> View<'a> {
        View {
            media: self._fields.0.unwrap(),
            records: self._fields.1,
            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>,
        >,
    ) -> View<'a> {
        View {
            media: self._fields.0.unwrap(),
            records: self._fields.1,
            extra_data: Some(extra_data),
        }
    }
}