// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: chat.bsky.moderation.getActorMetadata
//
// 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::{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::Did;
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::chat_bsky::moderation::get_actor_metadata;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GetActorMetadata<S: BosStr = DefaultStr> {
    pub actor: Did<S>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GetActorMetadataOutput<S: BosStr = DefaultStr> {
    pub all: get_actor_metadata::Metadata<S>,
    pub day: get_actor_metadata::Metadata<S>,
    pub month: get_actor_metadata::Metadata<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 Metadata<S: BosStr = DefaultStr> {
    pub convos: i64,
    pub convos_started: i64,
    pub messages_received: i64,
    pub messages_sent: i64,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/** Response marker for the `chat.bsky.moderation.getActorMetadata` query.

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `GetActorMetadataOutput<S>` for this endpoint.*/
pub struct GetActorMetadataResponse;
impl jacquard_common::xrpc::XrpcResp for GetActorMetadataResponse {
    const NSID: &'static str = "chat.bsky.moderation.getActorMetadata";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = GetActorMetadataOutput<S>;
    type Err = jacquard_common::xrpc::GenericError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for GetActorMetadata<S> {
    const NSID: &'static str = "chat.bsky.moderation.getActorMetadata";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = GetActorMetadataResponse;
}

/** Endpoint marker for the `chat.bsky.moderation.getActorMetadata` query.

Path: `/xrpc/chat.bsky.moderation.getActorMetadata`. The request payload type is `GetActorMetadata<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
pub struct GetActorMetadataRequest;
impl jacquard_common::xrpc::XrpcEndpoint for GetActorMetadataRequest {
    const PATH: &'static str = "/xrpc/chat.bsky.moderation.getActorMetadata";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<S: BosStr> = GetActorMetadata<S>;
    type Response = GetActorMetadataResponse;
}

impl<S: BosStr> LexiconSchema for Metadata<S> {
    fn nsid() -> &'static str {
        "chat.bsky.moderation.getActorMetadata"
    }
    fn def_name() -> &'static str {
        "metadata"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_chat_bsky_moderation_getActorMetadata()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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

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

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

impl<S: BosStr> GetActorMetadata<S> {
    /// Create a new builder for this type
    pub fn builder() -> GetActorMetadataBuilder<get_actor_metadata_state::Empty, S> {
        GetActorMetadataBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> GetActorMetadataBuilder<St, S>
where
    St: get_actor_metadata_state::State,
    St::Actor: get_actor_metadata_state::IsUnset,
{
    /// Set the `actor` field (required)
    pub fn actor(
        mut self,
        value: impl Into<Did<S>>,
    ) -> GetActorMetadataBuilder<get_actor_metadata_state::SetActor<St>, S> {
        self._fields.0 = Option::Some(value.into());
        GetActorMetadataBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> GetActorMetadataBuilder<St, S>
where
    St: get_actor_metadata_state::State,
    St::Actor: get_actor_metadata_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> GetActorMetadata<S> {
        GetActorMetadata {
            actor: self._fields.0.unwrap(),
        }
    }
}

pub mod metadata_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 Convos;
        type ConvosStarted;
        type MessagesReceived;
        type MessagesSent;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Convos = Unset;
        type ConvosStarted = Unset;
        type MessagesReceived = Unset;
        type MessagesSent = Unset;
    }
    ///State transition - sets the `convos` field to Set
    pub struct SetConvos<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetConvos<St> {}
    impl<St: State> State for SetConvos<St> {
        type Convos = Set<members::convos>;
        type ConvosStarted = St::ConvosStarted;
        type MessagesReceived = St::MessagesReceived;
        type MessagesSent = St::MessagesSent;
    }
    ///State transition - sets the `convos_started` field to Set
    pub struct SetConvosStarted<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetConvosStarted<St> {}
    impl<St: State> State for SetConvosStarted<St> {
        type Convos = St::Convos;
        type ConvosStarted = Set<members::convos_started>;
        type MessagesReceived = St::MessagesReceived;
        type MessagesSent = St::MessagesSent;
    }
    ///State transition - sets the `messages_received` field to Set
    pub struct SetMessagesReceived<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetMessagesReceived<St> {}
    impl<St: State> State for SetMessagesReceived<St> {
        type Convos = St::Convos;
        type ConvosStarted = St::ConvosStarted;
        type MessagesReceived = Set<members::messages_received>;
        type MessagesSent = St::MessagesSent;
    }
    ///State transition - sets the `messages_sent` field to Set
    pub struct SetMessagesSent<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetMessagesSent<St> {}
    impl<St: State> State for SetMessagesSent<St> {
        type Convos = St::Convos;
        type ConvosStarted = St::ConvosStarted;
        type MessagesReceived = St::MessagesReceived;
        type MessagesSent = Set<members::messages_sent>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `convos` field
        pub struct convos(());
        ///Marker type for the `convos_started` field
        pub struct convos_started(());
        ///Marker type for the `messages_received` field
        pub struct messages_received(());
        ///Marker type for the `messages_sent` field
        pub struct messages_sent(());
    }
}

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

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

impl<S: BosStr> Metadata<S> {
    /// Create a new builder for this type
    pub fn builder() -> MetadataBuilder<metadata_state::Empty, S> {
        MetadataBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> MetadataBuilder<St, S>
where
    St: metadata_state::State,
    St::Convos: metadata_state::IsUnset,
{
    /// Set the `convos` field (required)
    pub fn convos(
        mut self,
        value: impl Into<i64>,
    ) -> MetadataBuilder<metadata_state::SetConvos<St>, S> {
        self._fields.0 = Option::Some(value.into());
        MetadataBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> MetadataBuilder<St, S>
where
    St: metadata_state::State,
    St::ConvosStarted: metadata_state::IsUnset,
{
    /// Set the `convosStarted` field (required)
    pub fn convos_started(
        mut self,
        value: impl Into<i64>,
    ) -> MetadataBuilder<metadata_state::SetConvosStarted<St>, S> {
        self._fields.1 = Option::Some(value.into());
        MetadataBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> MetadataBuilder<St, S>
where
    St: metadata_state::State,
    St::MessagesReceived: metadata_state::IsUnset,
{
    /// Set the `messagesReceived` field (required)
    pub fn messages_received(
        mut self,
        value: impl Into<i64>,
    ) -> MetadataBuilder<metadata_state::SetMessagesReceived<St>, S> {
        self._fields.2 = Option::Some(value.into());
        MetadataBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> MetadataBuilder<St, S>
where
    St: metadata_state::State,
    St::MessagesSent: metadata_state::IsUnset,
{
    /// Set the `messagesSent` field (required)
    pub fn messages_sent(
        mut self,
        value: impl Into<i64>,
    ) -> MetadataBuilder<metadata_state::SetMessagesSent<St>, S> {
        self._fields.3 = Option::Some(value.into());
        MetadataBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> MetadataBuilder<St, S>
where
    St: metadata_state::State,
    St::Convos: metadata_state::IsSet,
    St::ConvosStarted: metadata_state::IsSet,
    St::MessagesReceived: metadata_state::IsSet,
    St::MessagesSent: metadata_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Metadata<S> {
        Metadata {
            convos: self._fields.0.unwrap(),
            convos_started: self._fields.1.unwrap(),
            messages_received: self._fields.2.unwrap(),
            messages_sent: self._fields.3.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>>) -> Metadata<S> {
        Metadata {
            convos: self._fields.0.unwrap(),
            convos_started: self._fields.1.unwrap(),
            messages_received: self._fields.2.unwrap(),
            messages_sent: self._fields.3.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_chat_bsky_moderation_getActorMetadata() -> 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("chat.bsky.moderation.getActorMetadata"),
        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("actor")]),
                            properties: {
                                #[allow(unused_mut)]
                                let mut map = BTreeMap::new();
                                map.insert(
                                    SmolStr::new_static("actor"),
                                    LexXrpcParametersProperty::String(LexString {
                                        format: Some(LexStringFormat::Did),
                                        ..Default::default()
                                    }),
                                );
                                map
                            },
                            ..Default::default()
                        }),
                    ),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("metadata"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("messagesSent"),
                            SmolStr::new_static("messagesReceived"),
                            SmolStr::new_static("convos"),
                            SmolStr::new_static("convosStarted")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("convos"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("convosStarted"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("messagesReceived"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("messagesSent"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}