// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: app.bsky.unspecced.getTaggedSuggestions
//
// 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::string::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::app_bsky::unspecced::get_tagged_suggestions;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetTaggedSuggestions;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetTaggedSuggestionsOutput<'a> {
    #[serde(borrow)]
    pub suggestions: Vec<get_tagged_suggestions::Suggestion<'a>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Suggestion<'a> {
    #[serde(borrow)]
    pub subject: UriValue<'a>,
    #[serde(borrow)]
    pub subject_type: SuggestionSubjectType<'a>,
    #[serde(borrow)]
    pub tag: CowStr<'a>,
}


#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum SuggestionSubjectType<'a> {
    Actor,
    Feed,
    Other(CowStr<'a>),
}

impl<'a> SuggestionSubjectType<'a> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Actor => "actor",
            Self::Feed => "feed",
            Self::Other(s) => s.as_ref(),
        }
    }
}

impl<'a> From<&'a str> for SuggestionSubjectType<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "actor" => Self::Actor,
            "feed" => Self::Feed,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for SuggestionSubjectType<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "actor" => Self::Actor,
            "feed" => Self::Feed,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> core::fmt::Display for SuggestionSubjectType<'a> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

impl<'a> AsRef<str> for SuggestionSubjectType<'a> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl<'a> serde::Serialize for SuggestionSubjectType<'a> {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de, 'a> serde::Deserialize<'de> for SuggestionSubjectType<'a>
where
    'de: 'a,
{
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = <&'de str>::deserialize(deserializer)?;
        Ok(Self::from(s))
    }
}

impl<'a> Default for SuggestionSubjectType<'a> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl jacquard_common::IntoStatic for SuggestionSubjectType<'_> {
    type Output = SuggestionSubjectType<'static>;
    fn into_static(self) -> Self::Output {
        match self {
            SuggestionSubjectType::Actor => SuggestionSubjectType::Actor,
            SuggestionSubjectType::Feed => SuggestionSubjectType::Feed,
            SuggestionSubjectType::Other(v) => {
                SuggestionSubjectType::Other(v.into_static())
            }
        }
    }
}

/// Response type for app.bsky.unspecced.getTaggedSuggestions
pub struct GetTaggedSuggestionsResponse;
impl jacquard_common::xrpc::XrpcResp for GetTaggedSuggestionsResponse {
    const NSID: &'static str = "app.bsky.unspecced.getTaggedSuggestions";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = GetTaggedSuggestionsOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

impl jacquard_common::xrpc::XrpcRequest for GetTaggedSuggestions {
    const NSID: &'static str = "app.bsky.unspecced.getTaggedSuggestions";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = GetTaggedSuggestionsResponse;
}

/// Endpoint type for app.bsky.unspecced.getTaggedSuggestions
pub struct GetTaggedSuggestionsRequest;
impl jacquard_common::xrpc::XrpcEndpoint for GetTaggedSuggestionsRequest {
    const PATH: &'static str = "/xrpc/app.bsky.unspecced.getTaggedSuggestions";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<'de> = GetTaggedSuggestions;
    type Response = GetTaggedSuggestionsResponse;
}

impl<'a> LexiconSchema for Suggestion<'a> {
    fn nsid() -> &'static str {
        "app.bsky.unspecced.getTaggedSuggestions"
    }
    fn def_name() -> &'static str {
        "suggestion"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_bsky_unspecced_getTaggedSuggestions()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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 SubjectType;
        type Subject;
        type Tag;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type SubjectType = Unset;
        type Subject = Unset;
        type Tag = Unset;
    }
    ///State transition - sets the `subject_type` field to Set
    pub struct SetSubjectType<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetSubjectType<S> {}
    impl<S: State> State for SetSubjectType<S> {
        type SubjectType = Set<members::subject_type>;
        type Subject = S::Subject;
        type Tag = S::Tag;
    }
    ///State transition - sets the `subject` field to Set
    pub struct SetSubject<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetSubject<S> {}
    impl<S: State> State for SetSubject<S> {
        type SubjectType = S::SubjectType;
        type Subject = Set<members::subject>;
        type Tag = S::Tag;
    }
    ///State transition - sets the `tag` field to Set
    pub struct SetTag<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetTag<S> {}
    impl<S: State> State for SetTag<S> {
        type SubjectType = S::SubjectType;
        type Subject = S::Subject;
        type Tag = Set<members::tag>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `subject_type` field
        pub struct subject_type(());
        ///Marker type for the `subject` field
        pub struct subject(());
        ///Marker type for the `tag` field
        pub struct tag(());
    }
}

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

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

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

impl<'a, S> SuggestionBuilder<'a, S>
where
    S: suggestion_state::State,
    S::Subject: suggestion_state::IsUnset,
{
    /// Set the `subject` field (required)
    pub fn subject(
        mut self,
        value: impl Into<UriValue<'a>>,
    ) -> SuggestionBuilder<'a, suggestion_state::SetSubject<S>> {
        self._fields.0 = Option::Some(value.into());
        SuggestionBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> SuggestionBuilder<'a, S>
where
    S: suggestion_state::State,
    S::SubjectType: suggestion_state::IsUnset,
{
    /// Set the `subjectType` field (required)
    pub fn subject_type(
        mut self,
        value: impl Into<SuggestionSubjectType<'a>>,
    ) -> SuggestionBuilder<'a, suggestion_state::SetSubjectType<S>> {
        self._fields.1 = Option::Some(value.into());
        SuggestionBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

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

impl<'a, S> SuggestionBuilder<'a, S>
where
    S: suggestion_state::State,
    S::SubjectType: suggestion_state::IsSet,
    S::Subject: suggestion_state::IsSet,
    S::Tag: suggestion_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Suggestion<'a> {
        Suggestion {
            subject: self._fields.0.unwrap(),
            subject_type: self._fields.1.unwrap(),
            tag: 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>,
        >,
    ) -> Suggestion<'a> {
        Suggestion {
            subject: self._fields.0.unwrap(),
            subject_type: self._fields.1.unwrap(),
            tag: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_app_bsky_unspecced_getTaggedSuggestions() -> 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("app.bsky.unspecced.getTaggedSuggestions"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcQuery(LexXrpcQuery {
                    parameters: Some(
                        LexXrpcQueryParameter::Params(LexXrpcParameters {
                            properties: {
                                #[allow(unused_mut)]
                                let mut map = BTreeMap::new();
                                map
                            },
                            ..Default::default()
                        }),
                    ),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("suggestion"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("tag"),
                            SmolStr::new_static("subjectType"),
                            SmolStr::new_static("subject")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("subject"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Uri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("subjectType"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("tag"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}