// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: network.slices.slice.getActors
//
// 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::{Did, Handle, Datetime};
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::network_slices::slice::get_actors;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Actor<S: BosStr = DefaultStr> {
    ///Decentralized identifier of the actor
    pub did: Did<S>,
    ///Human-readable handle of the actor
    #[serde(skip_serializing_if = "Option::is_none")]
    pub handle: Option<Handle<S>>,
    ///When this actor was indexed
    pub indexed_at: Datetime,
    ///AT-URI of the slice this actor is indexed in
    pub slice_uri: 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 GetActors<S: BosStr = DefaultStr> {
    ///Pagination cursor from previous response
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cursor: Option<S>,
    ///Maximum number of actors to return  Defaults to `50`.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "_default_get_actors_limit")]
    pub limit: Option<i64>,
    ///AT-URI of the slice to query
    pub slice: S,
    ///Flexible filtering conditions for querying actors
    #[serde(skip_serializing_if = "Option::is_none")]
    pub r#where: Option<Data<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 GetActorsOutput<S: BosStr = DefaultStr> {
    pub actors: Vec<get_actors::Actor<S>>,
    ///Pagination cursor for next page
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cursor: Option<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> LexiconSchema for Actor<S> {
    fn nsid() -> &'static str {
        "network.slices.slice.getActors"
    }
    fn def_name() -> &'static str {
        "actor"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_network_slices_slice_getActors()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

/** Response marker for the `network.slices.slice.getActors` procedure.

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `GetActorsOutput<S>` for this endpoint.*/
pub struct GetActorsResponse;
impl jacquard_common::xrpc::XrpcResp for GetActorsResponse {
    const NSID: &'static str = "network.slices.slice.getActors";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = GetActorsOutput<S>;
    type Err = jacquard_common::xrpc::GenericError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for GetActors<S> {
    const NSID: &'static str = "network.slices.slice.getActors";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Response = GetActorsResponse;
}

/** Endpoint marker for the `network.slices.slice.getActors` procedure.

Path: `/xrpc/network.slices.slice.getActors`. The request payload type is `GetActors<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
pub struct GetActorsRequest;
impl jacquard_common::xrpc::XrpcEndpoint for GetActorsRequest {
    const PATH: &'static str = "/xrpc/network.slices.slice.getActors";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Request<S: BosStr> = GetActors<S>;
    type Response = GetActorsResponse;
}

pub mod actor_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 Did;
        type IndexedAt;
        type SliceUri;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Did = Unset;
        type IndexedAt = Unset;
        type SliceUri = Unset;
    }
    ///State transition - sets the `did` field to Set
    pub struct SetDid<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetDid<St> {}
    impl<St: State> State for SetDid<St> {
        type Did = Set<members::did>;
        type IndexedAt = St::IndexedAt;
        type SliceUri = St::SliceUri;
    }
    ///State transition - sets the `indexed_at` field to Set
    pub struct SetIndexedAt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetIndexedAt<St> {}
    impl<St: State> State for SetIndexedAt<St> {
        type Did = St::Did;
        type IndexedAt = Set<members::indexed_at>;
        type SliceUri = St::SliceUri;
    }
    ///State transition - sets the `slice_uri` field to Set
    pub struct SetSliceUri<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetSliceUri<St> {}
    impl<St: State> State for SetSliceUri<St> {
        type Did = St::Did;
        type IndexedAt = St::IndexedAt;
        type SliceUri = Set<members::slice_uri>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `did` field
        pub struct did(());
        ///Marker type for the `indexed_at` field
        pub struct indexed_at(());
        ///Marker type for the `slice_uri` field
        pub struct slice_uri(());
    }
}

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

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

impl<S: BosStr> Actor<S> {
    /// Create a new builder for this type
    pub fn builder() -> ActorBuilder<actor_state::Empty, S> {
        ActorBuilder::builder()
    }
}

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

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

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

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

impl<St, S: BosStr> ActorBuilder<St, S>
where
    St: actor_state::State,
    St::IndexedAt: actor_state::IsUnset,
{
    /// Set the `indexedAt` field (required)
    pub fn indexed_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> ActorBuilder<actor_state::SetIndexedAt<St>, S> {
        self._fields.2 = Option::Some(value.into());
        ActorBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ActorBuilder<St, S>
where
    St: actor_state::State,
    St::SliceUri: actor_state::IsUnset,
{
    /// Set the `sliceUri` field (required)
    pub fn slice_uri(
        mut self,
        value: impl Into<S>,
    ) -> ActorBuilder<actor_state::SetSliceUri<St>, S> {
        self._fields.3 = Option::Some(value.into());
        ActorBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ActorBuilder<St, S>
where
    St: actor_state::State,
    St::Did: actor_state::IsSet,
    St::IndexedAt: actor_state::IsSet,
    St::SliceUri: actor_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Actor<S> {
        Actor {
            did: self._fields.0.unwrap(),
            handle: self._fields.1,
            indexed_at: self._fields.2.unwrap(),
            slice_uri: 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>>) -> Actor<S> {
        Actor {
            did: self._fields.0.unwrap(),
            handle: self._fields.1,
            indexed_at: self._fields.2.unwrap(),
            slice_uri: self._fields.3.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_network_slices_slice_getActors() -> 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("network.slices.slice.getActors"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("actor"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("did"), SmolStr::new_static("sliceUri"),
                            SmolStr::new_static("indexedAt")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("did"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Decentralized identifier of the actor"),
                                ),
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("handle"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Human-readable handle of the actor"),
                                ),
                                format: Some(LexStringFormat::Handle),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("indexedAt"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("When this actor was indexed"),
                                ),
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("sliceUri"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "AT-URI of the slice this actor is indexed in",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcProcedure(LexXrpcProcedure {
                    input: Some(LexXrpcBody {
                        encoding: CowStr::new_static("application/json"),
                        schema: Some(
                            LexXrpcBodySchema::Object(LexObject {
                                required: Some(vec![SmolStr::new_static("slice")]),
                                properties: {
                                    #[allow(unused_mut)]
                                    let mut map = BTreeMap::new();
                                    map.insert(
                                        SmolStr::new_static("cursor"),
                                        LexObjectProperty::String(LexString {
                                            description: Some(
                                                CowStr::new_static(
                                                    "Pagination cursor from previous response",
                                                ),
                                            ),
                                            ..Default::default()
                                        }),
                                    );
                                    map.insert(
                                        SmolStr::new_static("limit"),
                                        LexObjectProperty::Integer(LexInteger {
                                            minimum: Some(1i64),
                                            maximum: Some(100i64),
                                            ..Default::default()
                                        }),
                                    );
                                    map.insert(
                                        SmolStr::new_static("slice"),
                                        LexObjectProperty::String(LexString {
                                            description: Some(
                                                CowStr::new_static("AT-URI of the slice to query"),
                                            ),
                                            ..Default::default()
                                        }),
                                    );
                                    map.insert(
                                        SmolStr::new_static("where"),
                                        LexObjectProperty::Unknown(LexUnknown {
                                            ..Default::default()
                                        }),
                                    );
                                    map
                                },
                                ..Default::default()
                            }),
                        ),
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

fn _default_get_actors_limit() -> Option<i64> {
    Some(50i64)
}