// @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.

//! Generated bindings for the `win.tomo.x.pushat` Lexicon namespace/module.
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, 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::string::{Tid, UriValue};
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
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<S = DefaultStr> = Vec<pushat::DeviceListItem<S>>;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct DeviceListItem<S: BosStr = DefaultStr> {
    /// Defaults to `false`.
    #[serde(default = "_default_device_list_item_current")]
    pub current: bool,
    pub id: Tid,
    pub name: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct NotifyBody<S: BosStr = DefaultStr> {
    ///Body text of the notification.
    pub body: S,
    ///The URI of the icon displayed in the notification.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub icon: Option<UriValue<S>>,
    ///Experimental — do not use. The URI to open when the notification is clicked.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub link: Option<UriValue<S>>,
    ///Title text of the notification.
    pub title: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

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

/// Builder for constructing an instance of this type.
pub struct DeviceListItemBuilder<
    St: device_list_item_state::State,
    S: BosStr = DefaultStr,
> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<bool>, Option<Tid>, Option<S>),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

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

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

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

impl<St, S: BosStr> DeviceListItemBuilder<St, S>
where
    St: device_list_item_state::State,
    St::Current: device_list_item_state::IsSet,
    St::Id: device_list_item_state::IsSet,
    St::Name: device_list_item_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> DeviceListItem<S> {
        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<SmolStr, Data<S>>,
    ) -> DeviceListItem<S> {
        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()
    }
}