// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: win.tomo-x.pushat.defs
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

pub mod allow;
pub mod push_notify;


#[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::{Tid, UriValue};
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::win_tomo_x::pushat;
pub type DeviceList<'a> = Vec<pushat::DeviceListItem<'a>>;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct DeviceListItem<'a> {
    /// Defaults to `false`.
    #[serde(default = "_default_device_list_item_current")]
    pub current: bool,
    pub id: Tid,
    #[serde(borrow)]
    pub name: CowStr<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct NotifyBody<'a> {
    ///Body text of the notification.
    #[serde(borrow)]
    pub body: CowStr<'a>,
    ///The URI of the icon displayed in the notification.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub icon: Option<UriValue<'a>>,
    ///Experimental — do not use. The URI to open when the notification is clicked.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub link: Option<UriValue<'a>>,
    ///Title text of the notification.
    #[serde(borrow)]
    pub title: CowStr<'a>,
}

impl<'a> LexiconSchema for DeviceListItem<'a> {
    fn nsid() -> &'static str {
        "win.tomo-x.pushat.defs"
    }
    fn def_name() -> &'static str {
        "deviceListItem"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_win_tomo_x_pushat_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.name;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 300usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("name"),
                    max: 300usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.name;
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 30usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("name"),
                        max: 30usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}

impl<'a> LexiconSchema for NotifyBody<'a> {
    fn nsid() -> &'static str {
        "win.tomo-x.pushat.defs"
    }
    fn def_name() -> &'static str {
        "notifyBody"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_win_tomo_x_pushat_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

fn _default_device_list_item_current() -> bool {
    false
}

pub mod device_list_item_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 Name;
        type Current;
        type Id;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Name = Unset;
        type Current = Unset;
        type Id = Unset;
    }
    ///State transition - sets the `name` field to Set
    pub struct SetName<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetName<S> {}
    impl<S: State> State for SetName<S> {
        type Name = Set<members::name>;
        type Current = S::Current;
        type Id = S::Id;
    }
    ///State transition - sets the `current` field to Set
    pub struct SetCurrent<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCurrent<S> {}
    impl<S: State> State for SetCurrent<S> {
        type Name = S::Name;
        type Current = Set<members::current>;
        type Id = S::Id;
    }
    ///State transition - sets the `id` field to Set
    pub struct SetId<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetId<S> {}
    impl<S: State> State for SetId<S> {
        type Name = S::Name;
        type Current = S::Current;
        type Id = Set<members::id>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `name` field
        pub struct name(());
        ///Marker type for the `current` field
        pub struct current(());
        ///Marker type for the `id` field
        pub struct id(());
    }
}

/// Builder for constructing an instance of this type
pub struct DeviceListItemBuilder<'a, S: device_list_item_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<bool>, Option<Tid>, Option<CowStr<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> DeviceListItem<'a> {
    /// Create a new builder for this type
    pub fn new() -> DeviceListItemBuilder<'a, device_list_item_state::Empty> {
        DeviceListItemBuilder::new()
    }
}

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

impl<'a, S> DeviceListItemBuilder<'a, S>
where
    S: device_list_item_state::State,
    S::Current: device_list_item_state::IsUnset,
{
    /// Set the `current` field (required)
    pub fn current(
        mut self,
        value: impl Into<bool>,
    ) -> DeviceListItemBuilder<'a, device_list_item_state::SetCurrent<S>> {
        self._fields.0 = Option::Some(value.into());
        DeviceListItemBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> DeviceListItemBuilder<'a, S>
where
    S: device_list_item_state::State,
    S::Id: device_list_item_state::IsUnset,
{
    /// Set the `id` field (required)
    pub fn id(
        mut self,
        value: impl Into<Tid>,
    ) -> DeviceListItemBuilder<'a, device_list_item_state::SetId<S>> {
        self._fields.1 = Option::Some(value.into());
        DeviceListItemBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> DeviceListItemBuilder<'a, S>
where
    S: device_list_item_state::State,
    S::Name: device_list_item_state::IsUnset,
{
    /// Set the `name` field (required)
    pub fn name(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> DeviceListItemBuilder<'a, device_list_item_state::SetName<S>> {
        self._fields.2 = Option::Some(value.into());
        DeviceListItemBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> DeviceListItemBuilder<'a, S>
where
    S: device_list_item_state::State,
    S::Name: device_list_item_state::IsSet,
    S::Current: device_list_item_state::IsSet,
    S::Id: device_list_item_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> DeviceListItem<'a> {
        DeviceListItem {
            current: self._fields.0.unwrap(),
            id: self._fields.1.unwrap(),
            name: 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>,
        >,
    ) -> DeviceListItem<'a> {
        DeviceListItem {
            current: self._fields.0.unwrap(),
            id: self._fields.1.unwrap(),
            name: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_win_tomo_x_pushat_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("win.tomo-x.pushat.defs"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("deviceList"),
                LexUserType::Array(LexArray {
                    items: LexArrayItem::Ref(LexRef {
                        r#ref: CowStr::new_static("#deviceListItem"),
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("deviceListItem"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("name"), SmolStr::new_static("id"),
                            SmolStr::new_static("current")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("current"),
                            LexObjectProperty::Boolean(LexBoolean {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("id"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Tid),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("name"),
                            LexObjectProperty::String(LexString {
                                max_length: Some(300usize),
                                max_graphemes: Some(30usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("notifyBody"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("title"), SmolStr::new_static("body")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("body"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Body text of the notification."),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("icon"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The URI of the icon displayed in the notification.",
                                    ),
                                ),
                                format: Some(LexStringFormat::Uri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("link"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Experimental — do not use. The URI to open when the notification is clicked.",
                                    ),
                                ),
                                format: Some(LexStringFormat::Uri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("title"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Title text of the notification."),
                                ),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}