// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: com.atproto.temp.checkHandleAvailability
//
// 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::string::{Handle, Datetime};
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, 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::com_atproto::temp::check_handle_availability;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct CheckHandleAvailability<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub birth_date: Option<Datetime>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub email: Option<S>,
    pub handle: Handle<S>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct CheckHandleAvailabilityOutput<S: BosStr = DefaultStr> {
    ///Echo of the input handle.
    pub handle: Handle<S>,
    pub result: CheckHandleAvailabilityOutputResult<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum CheckHandleAvailabilityOutputResult<S: BosStr = DefaultStr> {
    #[serde(rename = "com.atproto.temp.checkHandleAvailability#resultAvailable")]
    ResultAvailable(Box<check_handle_availability::ResultAvailable<S>>),
    #[serde(rename = "com.atproto.temp.checkHandleAvailability#resultUnavailable")]
    ResultUnavailable(Box<check_handle_availability::ResultUnavailable<S>>),
}


#[derive(
    Serialize,
    Deserialize,
    Debug,
    Clone,
    PartialEq,
    Eq,
    thiserror::Error,
    miette::Diagnostic
)]

#[serde(tag = "error", content = "message")]
pub enum CheckHandleAvailabilityError {
    /// An invalid email was provided.
    #[serde(rename = "InvalidEmail")]
    InvalidEmail(Option<SmolStr>),
    /// Catch-all for unknown error codes.
    #[serde(untagged)]
    Other { error: SmolStr, message: Option<SmolStr> },
}

impl core::fmt::Display for CheckHandleAvailabilityError {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::InvalidEmail(msg) => {
                write!(f, "InvalidEmail")?;
                if let Some(msg) = msg {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
            Self::Other { error, message } => {
                write!(f, "{}", error)?;
                if let Some(msg) = message {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
        }
    }
}

/// Indicates the provided handle is available.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ResultAvailable<S: BosStr = DefaultStr> {
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Indicates the provided handle is unavailable and gives suggestions of available handles.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ResultUnavailable<S: BosStr = DefaultStr> {
    ///List of suggested handles based on the provided inputs.
    pub suggestions: Vec<check_handle_availability::Suggestion<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)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Suggestion<S: BosStr = DefaultStr> {
    pub handle: Handle<S>,
    ///Method used to build this suggestion. Should be considered opaque to clients. Can be used for metrics.
    pub method: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/** Response marker for the `com.atproto.temp.checkHandleAvailability` query.

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `CheckHandleAvailabilityOutput<S>` for this endpoint.*/
pub struct CheckHandleAvailabilityResponse;
impl jacquard_common::xrpc::XrpcResp for CheckHandleAvailabilityResponse {
    const NSID: &'static str = "com.atproto.temp.checkHandleAvailability";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = CheckHandleAvailabilityOutput<S>;
    type Err = CheckHandleAvailabilityError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for CheckHandleAvailability<S> {
    const NSID: &'static str = "com.atproto.temp.checkHandleAvailability";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = CheckHandleAvailabilityResponse;
}

/** Endpoint marker for the `com.atproto.temp.checkHandleAvailability` query.

Path: `/xrpc/com.atproto.temp.checkHandleAvailability`. The request payload type is `CheckHandleAvailability<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
pub struct CheckHandleAvailabilityRequest;
impl jacquard_common::xrpc::XrpcEndpoint for CheckHandleAvailabilityRequest {
    const PATH: &'static str = "/xrpc/com.atproto.temp.checkHandleAvailability";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<S: BosStr> = CheckHandleAvailability<S>;
    type Response = CheckHandleAvailabilityResponse;
}

impl<S: BosStr> LexiconSchema for ResultAvailable<S> {
    fn nsid() -> &'static str {
        "com.atproto.temp.checkHandleAvailability"
    }
    fn def_name() -> &'static str {
        "resultAvailable"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_atproto_temp_checkHandleAvailability()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for ResultUnavailable<S> {
    fn nsid() -> &'static str {
        "com.atproto.temp.checkHandleAvailability"
    }
    fn def_name() -> &'static str {
        "resultUnavailable"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_atproto_temp_checkHandleAvailability()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Suggestion<S> {
    fn nsid() -> &'static str {
        "com.atproto.temp.checkHandleAvailability"
    }
    fn def_name() -> &'static str {
        "suggestion"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_atproto_temp_checkHandleAvailability()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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

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

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

impl<S: BosStr> CheckHandleAvailability<S> {
    /// Create a new builder for this type
    pub fn builder() -> CheckHandleAvailabilityBuilder<
        check_handle_availability_state::Empty,
        S,
    > {
        CheckHandleAvailabilityBuilder::builder()
    }
}

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

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

impl<
    St: check_handle_availability_state::State,
    S: BosStr,
> CheckHandleAvailabilityBuilder<St, S> {
    /// Set the `birthDate` field (optional)
    pub fn birth_date(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `birthDate` field to an Option value (optional)
    pub fn maybe_birth_date(mut self, value: Option<Datetime>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<
    St: check_handle_availability_state::State,
    S: BosStr,
> CheckHandleAvailabilityBuilder<St, S> {
    /// Set the `email` field (optional)
    pub fn email(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `email` field to an Option value (optional)
    pub fn maybe_email(mut self, value: Option<S>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St, S: BosStr> CheckHandleAvailabilityBuilder<St, S>
where
    St: check_handle_availability_state::State,
    St::Handle: check_handle_availability_state::IsUnset,
{
    /// Set the `handle` field (required)
    pub fn handle(
        mut self,
        value: impl Into<Handle<S>>,
    ) -> CheckHandleAvailabilityBuilder<
        check_handle_availability_state::SetHandle<St>,
        S,
    > {
        self._fields.2 = Option::Some(value.into());
        CheckHandleAvailabilityBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> CheckHandleAvailabilityBuilder<St, S>
where
    St: check_handle_availability_state::State,
    St::Handle: check_handle_availability_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> CheckHandleAvailability<S> {
        CheckHandleAvailability {
            birth_date: self._fields.0,
            email: self._fields.1,
            handle: self._fields.2.unwrap(),
        }
    }
}

fn lexicon_doc_com_atproto_temp_checkHandleAvailability() -> 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("com.atproto.temp.checkHandleAvailability"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcQuery(LexXrpcQuery {
                    parameters: Some(
                        LexXrpcQueryParameter::Params(LexXrpcParameters {
                            required: Some(vec![SmolStr::new_static("handle")]),
                            properties: {
                                #[allow(unused_mut)]
                                let mut map = BTreeMap::new();
                                map.insert(
                                    SmolStr::new_static("birthDate"),
                                    LexXrpcParametersProperty::String(LexString {
                                        description: Some(
                                            CowStr::new_static(
                                                "User-provided birth date. Might be used to build handle suggestions.",
                                            ),
                                        ),
                                        format: Some(LexStringFormat::Datetime),
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("email"),
                                    LexXrpcParametersProperty::String(LexString {
                                        description: Some(
                                            CowStr::new_static(
                                                "User-provided email. Might be used to build handle suggestions.",
                                            ),
                                        ),
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("handle"),
                                    LexXrpcParametersProperty::String(LexString {
                                        description: Some(
                                            CowStr::new_static(
                                                "Tentative handle. Will be checked for availability or used to build handle suggestions.",
                                            ),
                                        ),
                                        format: Some(LexStringFormat::Handle),
                                        ..Default::default()
                                    }),
                                );
                                map
                            },
                            ..Default::default()
                        }),
                    ),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("resultAvailable"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Indicates the provided handle is available."),
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("resultUnavailable"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Indicates the provided handle is unavailable and gives suggestions of available handles.",
                        ),
                    ),
                    required: Some(vec![SmolStr::new_static("suggestions")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("suggestions"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static(
                                        "List of suggested handles based on the provided inputs.",
                                    ),
                                ),
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("#suggestion"),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("suggestion"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("handle"), SmolStr::new_static("method")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("handle"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Handle),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("method"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Method used to build this suggestion. Should be considered opaque to clients. Can be used for metrics.",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

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

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

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

impl<S: BosStr> ResultUnavailable<S> {
    /// Create a new builder for this type
    pub fn builder() -> ResultUnavailableBuilder<result_unavailable_state::Empty, S> {
        ResultUnavailableBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> ResultUnavailableBuilder<St, S>
where
    St: result_unavailable_state::State,
    St::Suggestions: result_unavailable_state::IsUnset,
{
    /// Set the `suggestions` field (required)
    pub fn suggestions(
        mut self,
        value: impl Into<Vec<check_handle_availability::Suggestion<S>>>,
    ) -> ResultUnavailableBuilder<result_unavailable_state::SetSuggestions<St>, S> {
        self._fields.0 = Option::Some(value.into());
        ResultUnavailableBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ResultUnavailableBuilder<St, S>
where
    St: result_unavailable_state::State,
    St::Suggestions: result_unavailable_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ResultUnavailable<S> {
        ResultUnavailable {
            suggestions: self._fields.0.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>>,
    ) -> ResultUnavailable<S> {
        ResultUnavailable {
            suggestions: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod suggestion_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 Handle;
        type Method;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Handle = Unset;
        type Method = Unset;
    }
    ///State transition - sets the `handle` field to Set
    pub struct SetHandle<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetHandle<St> {}
    impl<St: State> State for SetHandle<St> {
        type Handle = Set<members::handle>;
        type Method = St::Method;
    }
    ///State transition - sets the `method` field to Set
    pub struct SetMethod<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetMethod<St> {}
    impl<St: State> State for SetMethod<St> {
        type Handle = St::Handle;
        type Method = Set<members::method>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `handle` field
        pub struct handle(());
        ///Marker type for the `method` field
        pub struct method(());
    }
}

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

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

impl<S: BosStr> Suggestion<S> {
    /// Create a new builder for this type
    pub fn builder() -> SuggestionBuilder<suggestion_state::Empty, S> {
        SuggestionBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> SuggestionBuilder<St, S>
where
    St: suggestion_state::State,
    St::Handle: suggestion_state::IsUnset,
{
    /// Set the `handle` field (required)
    pub fn handle(
        mut self,
        value: impl Into<Handle<S>>,
    ) -> SuggestionBuilder<suggestion_state::SetHandle<St>, S> {
        self._fields.0 = Option::Some(value.into());
        SuggestionBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> SuggestionBuilder<St, S>
where
    St: suggestion_state::State,
    St::Method: suggestion_state::IsUnset,
{
    /// Set the `method` field (required)
    pub fn method(
        mut self,
        value: impl Into<S>,
    ) -> SuggestionBuilder<suggestion_state::SetMethod<St>, S> {
        self._fields.1 = Option::Some(value.into());
        SuggestionBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> SuggestionBuilder<St, S>
where
    St: suggestion_state::State,
    St::Handle: suggestion_state::IsSet,
    St::Method: suggestion_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Suggestion<S> {
        Suggestion {
            handle: self._fields.0.unwrap(),
            method: 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<SmolStr, Data<S>>,
    ) -> Suggestion<S> {
        Suggestion {
            handle: self._fields.0.unwrap(),
            method: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}