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

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::string::{Did, AtUri, Nsid, Cid, 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_slice_records;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct IndexedRecord<'a> {
    ///Content identifier of the record
    #[serde(borrow)]
    pub cid: Cid<'a>,
    ///NSID of the collection this record belongs to
    #[serde(borrow)]
    pub collection: Nsid<'a>,
    ///DID of the record creator
    #[serde(borrow)]
    pub did: Did<'a>,
    ///When this record was indexed
    pub indexed_at: Datetime,
    ///AT-URI of the record
    #[serde(borrow)]
    pub uri: AtUri<'a>,
    ///The record value/content
    #[serde(borrow)]
    pub value: Data<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct GetSliceRecords<'a> {
    ///Pagination cursor from previous response
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cursor: Option<CowStr<'a>>,
    ///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
    #[serde(borrow)]
    pub slice: CowStr<'a>,
    ///Sorting configuration for result ordering
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub sort_by: Option<Data<'a>>,
    ///Flexible filtering conditions for querying records
    #[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 GetSliceRecordsOutput<'a> {
    ///Pagination cursor for next page
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cursor: Option<CowStr<'a>>,
    #[serde(borrow)]
    pub records: Vec<get_slice_records::IndexedRecord<'a>>,
}

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

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

/// Builder for constructing an instance of this type
pub struct IndexedRecordBuilder<'a, S: indexed_record_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<Cid<'a>>,
        Option<Nsid<'a>>,
        Option<Did<'a>>,
        Option<Datetime>,
        Option<AtUri<'a>>,
        Option<Data<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

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

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

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

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

impl<'a, S> IndexedRecordBuilder<'a, S>
where
    S: indexed_record_state::State,
    S::Value: indexed_record_state::IsSet,
    S::Uri: indexed_record_state::IsSet,
    S::Cid: indexed_record_state::IsSet,
    S::IndexedAt: indexed_record_state::IsSet,
    S::Did: indexed_record_state::IsSet,
    S::Collection: indexed_record_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> IndexedRecord<'a> {
        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<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
    ) -> IndexedRecord<'a> {
        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)
}