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

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::string::{Did, Handle, Datetime};
use jacquard_common::types::value::Data;
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::network_slices::slice::get_actors;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Actor<'a> {
    ///Decentralized identifier of the actor
    #[serde(borrow)]
    pub did: Did<'a>,
    ///Human-readable handle of the actor
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub handle: Option<Handle<'a>>,
    ///When this actor was indexed
    pub indexed_at: Datetime,
    ///AT-URI of the slice this actor is indexed in
    #[serde(borrow)]
    pub slice_uri: CowStr<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct GetActors<'a> {
    ///Pagination cursor from previous response
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cursor: Option<CowStr<'a>>,
    ///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
    #[serde(borrow)]
    pub slice: CowStr<'a>,
    ///Flexible filtering conditions for querying actors
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub r#where: Option<Data<'a>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetActorsOutput<'a> {
    #[serde(borrow)]
    pub actors: Vec<get_actors::Actor<'a>>,
    ///Pagination cursor for next page
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cursor: Option<CowStr<'a>>,
}

impl<'a> LexiconSchema for Actor<'a> {
    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 type for network.slices.slice.getActors
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<'de> = GetActorsOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

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

/// Builder for constructing an instance of this type
pub struct ActorBuilder<'a, S: actor_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<Did<'a>>, Option<Handle<'a>>, Option<Datetime>, Option<CowStr<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

impl<'a, S: actor_state::State> ActorBuilder<'a, S> {
    /// Set the `handle` field (optional)
    pub fn handle(mut self, value: impl Into<Option<Handle<'a>>>) -> 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<'a>>) -> Self {
        self._fields.1 = value;
        self
    }
}

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

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

impl<'a, S> ActorBuilder<'a, S>
where
    S: actor_state::State,
    S::IndexedAt: actor_state::IsSet,
    S::SliceUri: actor_state::IsSet,
    S::Did: actor_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Actor<'a> {
        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<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
    ) -> Actor<'a> {
        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)
}