// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: network.slices.slice.getSliceRecords
//
// 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, AtUri, Nsid, Cid, 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_slice_records;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct IndexedRecord<S: BosStr = DefaultStr> {
    ///Content identifier of the record
    pub cid: Cid<S>,
    ///NSID of the collection this record belongs to
    pub collection: Nsid<S>,
    ///DID of the record creator
    pub did: Did<S>,
    ///When this record was indexed
    pub indexed_at: Datetime,
    ///AT-URI of the record
    pub uri: AtUri<S>,
    ///The record value/content
    pub value: 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, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GetSliceRecords<S: BosStr = DefaultStr> {
    ///Pagination cursor from previous response
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cursor: Option<S>,
    ///Maximum number of records to return  Defaults to `50`.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "_default_get_slice_records_limit")]
    pub limit: Option<i64>,
    ///AT-URI of the slice to query
    pub slice: S,
    ///Sorting configuration for result ordering
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sort_by: Option<Data<S>>,
    ///Flexible filtering conditions for querying records
    #[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 GetSliceRecordsOutput<S: BosStr = DefaultStr> {
    ///Pagination cursor for next page
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cursor: Option<S>,
    pub records: Vec<get_slice_records::IndexedRecord<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

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

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

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

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

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

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

pub mod indexed_record_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 Cid;
        type Collection;
        type Did;
        type IndexedAt;
        type Uri;
        type Value;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Cid = Unset;
        type Collection = Unset;
        type Did = Unset;
        type IndexedAt = Unset;
        type Uri = Unset;
        type Value = Unset;
    }
    ///State transition - sets the `cid` field to Set
    pub struct SetCid<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCid<St> {}
    impl<St: State> State for SetCid<St> {
        type Cid = Set<members::cid>;
        type Collection = St::Collection;
        type Did = St::Did;
        type IndexedAt = St::IndexedAt;
        type Uri = St::Uri;
        type Value = St::Value;
    }
    ///State transition - sets the `collection` field to Set
    pub struct SetCollection<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCollection<St> {}
    impl<St: State> State for SetCollection<St> {
        type Cid = St::Cid;
        type Collection = Set<members::collection>;
        type Did = St::Did;
        type IndexedAt = St::IndexedAt;
        type Uri = St::Uri;
        type Value = St::Value;
    }
    ///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 Cid = St::Cid;
        type Collection = St::Collection;
        type Did = Set<members::did>;
        type IndexedAt = St::IndexedAt;
        type Uri = St::Uri;
        type Value = St::Value;
    }
    ///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 Cid = St::Cid;
        type Collection = St::Collection;
        type Did = St::Did;
        type IndexedAt = Set<members::indexed_at>;
        type Uri = St::Uri;
        type Value = St::Value;
    }
    ///State transition - sets the `uri` field to Set
    pub struct SetUri<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetUri<St> {}
    impl<St: State> State for SetUri<St> {
        type Cid = St::Cid;
        type Collection = St::Collection;
        type Did = St::Did;
        type IndexedAt = St::IndexedAt;
        type Uri = Set<members::uri>;
        type Value = St::Value;
    }
    ///State transition - sets the `value` field to Set
    pub struct SetValue<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetValue<St> {}
    impl<St: State> State for SetValue<St> {
        type Cid = St::Cid;
        type Collection = St::Collection;
        type Did = St::Did;
        type IndexedAt = St::IndexedAt;
        type Uri = St::Uri;
        type Value = Set<members::value>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `cid` field
        pub struct cid(());
        ///Marker type for the `collection` field
        pub struct collection(());
        ///Marker type for the `did` field
        pub struct did(());
        ///Marker type for the `indexed_at` field
        pub struct indexed_at(());
        ///Marker type for the `uri` field
        pub struct uri(());
        ///Marker type for the `value` field
        pub struct value(());
    }
}

/// Builder for constructing an instance of this type.
pub struct IndexedRecordBuilder<
    St: indexed_record_state::State,
    S: BosStr = DefaultStr,
> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<Cid<S>>,
        Option<Nsid<S>>,
        Option<Did<S>>,
        Option<Datetime>,
        Option<AtUri<S>>,
        Option<Data<S>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> IndexedRecord<S> {
    /// Create a new builder for this type
    pub fn builder() -> IndexedRecordBuilder<indexed_record_state::Empty, S> {
        IndexedRecordBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> IndexedRecordBuilder<St, S>
where
    St: indexed_record_state::State,
    St::Cid: indexed_record_state::IsUnset,
{
    /// Set the `cid` field (required)
    pub fn cid(
        mut self,
        value: impl Into<Cid<S>>,
    ) -> IndexedRecordBuilder<indexed_record_state::SetCid<St>, S> {
        self._fields.0 = Option::Some(value.into());
        IndexedRecordBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> IndexedRecordBuilder<St, S>
where
    St: indexed_record_state::State,
    St::Collection: indexed_record_state::IsUnset,
{
    /// Set the `collection` field (required)
    pub fn collection(
        mut self,
        value: impl Into<Nsid<S>>,
    ) -> IndexedRecordBuilder<indexed_record_state::SetCollection<St>, S> {
        self._fields.1 = Option::Some(value.into());
        IndexedRecordBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

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

impl<St, S: BosStr> IndexedRecordBuilder<St, S>
where
    St: indexed_record_state::State,
    St::Uri: indexed_record_state::IsUnset,
{
    /// Set the `uri` field (required)
    pub fn uri(
        mut self,
        value: impl Into<AtUri<S>>,
    ) -> IndexedRecordBuilder<indexed_record_state::SetUri<St>, S> {
        self._fields.4 = Option::Some(value.into());
        IndexedRecordBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> IndexedRecordBuilder<St, S>
where
    St: indexed_record_state::State,
    St::Value: indexed_record_state::IsUnset,
{
    /// Set the `value` field (required)
    pub fn value(
        mut self,
        value: impl Into<Data<S>>,
    ) -> IndexedRecordBuilder<indexed_record_state::SetValue<St>, S> {
        self._fields.5 = Option::Some(value.into());
        IndexedRecordBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> IndexedRecordBuilder<St, S>
where
    St: indexed_record_state::State,
    St::Cid: indexed_record_state::IsSet,
    St::Collection: indexed_record_state::IsSet,
    St::Did: indexed_record_state::IsSet,
    St::IndexedAt: indexed_record_state::IsSet,
    St::Uri: indexed_record_state::IsSet,
    St::Value: indexed_record_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> IndexedRecord<S> {
        IndexedRecord {
            cid: self._fields.0.unwrap(),
            collection: self._fields.1.unwrap(),
            did: self._fields.2.unwrap(),
            indexed_at: self._fields.3.unwrap(),
            uri: self._fields.4.unwrap(),
            value: self._fields.5.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>>,
    ) -> IndexedRecord<S> {
        IndexedRecord {
            cid: self._fields.0.unwrap(),
            collection: self._fields.1.unwrap(),
            did: self._fields.2.unwrap(),
            indexed_at: self._fields.3.unwrap(),
            uri: self._fields.4.unwrap(),
            value: self._fields.5.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_network_slices_slice_getSliceRecords() -> 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.getSliceRecords"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("indexedRecord"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("uri"), SmolStr::new_static("cid"),
                            SmolStr::new_static("did"),
                            SmolStr::new_static("collection"),
                            SmolStr::new_static("value"),
                            SmolStr::new_static("indexedAt")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("cid"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Content identifier of the record"),
                                ),
                                format: Some(LexStringFormat::Cid),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("collection"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "NSID of the collection this record belongs to",
                                    ),
                                ),
                                format: Some(LexStringFormat::Nsid),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("did"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("DID of the record creator"),
                                ),
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("indexedAt"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("When this record was indexed"),
                                ),
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("uri"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("AT-URI of the record"),
                                ),
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("value"),
                            LexObjectProperty::Unknown(LexUnknown {
                                ..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("sortBy"),
                                        LexObjectProperty::Unknown(LexUnknown {
                                            ..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_slice_records_limit() -> Option<i64> {
    Some(50i64)
}