// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: zone.stratos.repo.hydrateRecords
//
// 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;

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

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct HydrateRecords<'a> {
    ///Array of AT-URIs to hydrate (max 100)
    #[serde(borrow)]
    pub uris: Vec<AtUri<'a>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct HydrateRecordsOutput<'a> {
    ///URIs blocked due to boundary restrictions
    #[serde(borrow)]
    pub blocked: Vec<AtUri<'a>>,
    ///URIs that were not found
    #[serde(borrow)]
    pub not_found: Vec<AtUri<'a>>,
    ///Successfully hydrated records
    #[serde(borrow)]
    pub records: Vec<hydrate_records::RecordView<'a>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct RecordView<'a> {
    #[serde(borrow)]
    pub cid: Cid<'a>,
    #[serde(borrow)]
    pub uri: AtUri<'a>,
    #[serde(borrow)]
    pub value: Data<'a>,
}

/// Response type for zone.stratos.repo.hydrateRecords
pub struct HydrateRecordsResponse;
impl jacquard_common::xrpc::XrpcResp for HydrateRecordsResponse {
    const NSID: &'static str = "zone.stratos.repo.hydrateRecords";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = HydrateRecordsOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for HydrateRecords<'a> {
    const NSID: &'static str = "zone.stratos.repo.hydrateRecords";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Response = HydrateRecordsResponse;
}

/// Endpoint type for zone.stratos.repo.hydrateRecords
pub struct HydrateRecordsRequest;
impl jacquard_common::xrpc::XrpcEndpoint for HydrateRecordsRequest {
    const PATH: &'static str = "/xrpc/zone.stratos.repo.hydrateRecords";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Request<'de> = HydrateRecords<'de>;
    type Response = HydrateRecordsResponse;
}

impl<'a> LexiconSchema for RecordView<'a> {
    fn nsid() -> &'static str {
        "zone.stratos.repo.hydrateRecords"
    }
    fn def_name() -> &'static str {
        "recordView"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_zone_stratos_repo_hydrateRecords()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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

/// Builder for constructing an instance of this type
pub struct HydrateRecordsBuilder<'a, S: hydrate_records_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<Vec<AtUri<'a>>>,),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> HydrateRecords<'a> {
    /// Create a new builder for this type
    pub fn new() -> HydrateRecordsBuilder<'a, hydrate_records_state::Empty> {
        HydrateRecordsBuilder::new()
    }
}

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

impl<'a, S> HydrateRecordsBuilder<'a, S>
where
    S: hydrate_records_state::State,
    S::Uris: hydrate_records_state::IsUnset,
{
    /// Set the `uris` field (required)
    pub fn uris(
        mut self,
        value: impl Into<Vec<AtUri<'a>>>,
    ) -> HydrateRecordsBuilder<'a, hydrate_records_state::SetUris<S>> {
        self._fields.0 = Option::Some(value.into());
        HydrateRecordsBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> HydrateRecordsBuilder<'a, S>
where
    S: hydrate_records_state::State,
    S::Uris: hydrate_records_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> HydrateRecords<'a> {
        HydrateRecords {
            uris: self._fields.0.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>>,
    ) -> HydrateRecords<'a> {
        HydrateRecords {
            uris: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod record_view_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 Value;
        type Uri;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Cid = Unset;
        type Value = Unset;
        type Uri = Unset;
    }
    ///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 Cid = Set<members::cid>;
        type Value = S::Value;
        type Uri = S::Uri;
    }
    ///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 Cid = S::Cid;
        type Value = Set<members::value>;
        type Uri = S::Uri;
    }
    ///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 Cid = S::Cid;
        type Value = S::Value;
        type Uri = Set<members::uri>;
    }
    /// 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 `value` field
        pub struct value(());
        ///Marker type for the `uri` field
        pub struct uri(());
    }
}

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

impl<'a> RecordView<'a> {
    /// Create a new builder for this type
    pub fn new() -> RecordViewBuilder<'a, record_view_state::Empty> {
        RecordViewBuilder::new()
    }
}

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

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

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

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

impl<'a, S> RecordViewBuilder<'a, S>
where
    S: record_view_state::State,
    S::Cid: record_view_state::IsSet,
    S::Value: record_view_state::IsSet,
    S::Uri: record_view_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> RecordView<'a> {
        RecordView {
            cid: self._fields.0.unwrap(),
            uri: self._fields.1.unwrap(),
            value: self._fields.2.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>>,
    ) -> RecordView<'a> {
        RecordView {
            cid: self._fields.0.unwrap(),
            uri: self._fields.1.unwrap(),
            value: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_zone_stratos_repo_hydrateRecords() -> 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("zone.stratos.repo.hydrateRecords"),
        defs: {
            let mut map = BTreeMap::new();
            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("uris")]),
                                properties: {
                                    #[allow(unused_mut)]
                                    let mut map = BTreeMap::new();
                                    map.insert(
                                        SmolStr::new_static("uris"),
                                        LexObjectProperty::Array(LexArray {
                                            description: Some(
                                                CowStr::new_static("Array of AT-URIs to hydrate (max 100)"),
                                            ),
                                            items: LexArrayItem::String(LexString {
                                                format: Some(LexStringFormat::AtUri),
                                                ..Default::default()
                                            }),
                                            max_length: Some(100usize),
                                            ..Default::default()
                                        }),
                                    );
                                    map
                                },
                                ..Default::default()
                            }),
                        ),
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("recordView"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("uri"), SmolStr::new_static("cid"),
                            SmolStr::new_static("value")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("cid"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Cid),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("uri"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("value"),
                            LexObjectProperty::Unknown(LexUnknown {
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}