// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: sh.tangled.repo.listSecrets
//
// 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, Datetime};
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::sh_tangled::repo::list_secrets;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ListSecrets<'a> {
    #[serde(borrow)]
    pub repo: AtUri<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ListSecretsOutput<'a> {
    #[serde(borrow)]
    pub secrets: Vec<list_secrets::Secret<'a>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Secret<'a> {
    pub created_at: Datetime,
    #[serde(borrow)]
    pub created_by: Did<'a>,
    #[serde(borrow)]
    pub key: CowStr<'a>,
    #[serde(borrow)]
    pub repo: AtUri<'a>,
}

/// Response type for sh.tangled.repo.listSecrets
pub struct ListSecretsResponse;
impl jacquard_common::xrpc::XrpcResp for ListSecretsResponse {
    const NSID: &'static str = "sh.tangled.repo.listSecrets";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = ListSecretsOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for ListSecrets<'a> {
    const NSID: &'static str = "sh.tangled.repo.listSecrets";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = ListSecretsResponse;
}

/// Endpoint type for sh.tangled.repo.listSecrets
pub struct ListSecretsRequest;
impl jacquard_common::xrpc::XrpcEndpoint for ListSecretsRequest {
    const PATH: &'static str = "/xrpc/sh.tangled.repo.listSecrets";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<'de> = ListSecrets<'de>;
    type Response = ListSecretsResponse;
}

impl<'a> LexiconSchema for Secret<'a> {
    fn nsid() -> &'static str {
        "sh.tangled.repo.listSecrets"
    }
    fn def_name() -> &'static str {
        "secret"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_tangled_repo_listSecrets()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.key;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 50usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("key"),
                    max: 50usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.key;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) < 1usize {
                return Err(ConstraintError::MinLength {
                    path: ValidationPath::from_field("key"),
                    min: 1usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

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

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

impl<'a> ListSecrets<'a> {
    /// Create a new builder for this type
    pub fn new() -> ListSecretsBuilder<'a, list_secrets_state::Empty> {
        ListSecretsBuilder::new()
    }
}

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

impl<'a, S> ListSecretsBuilder<'a, S>
where
    S: list_secrets_state::State,
    S::Repo: list_secrets_state::IsUnset,
{
    /// Set the `repo` field (required)
    pub fn repo(
        mut self,
        value: impl Into<AtUri<'a>>,
    ) -> ListSecretsBuilder<'a, list_secrets_state::SetRepo<S>> {
        self._fields.0 = Option::Some(value.into());
        ListSecretsBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> ListSecretsBuilder<'a, S>
where
    S: list_secrets_state::State,
    S::Repo: list_secrets_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> ListSecrets<'a> {
        ListSecrets {
            repo: self._fields.0.unwrap(),
        }
    }
}

pub mod secret_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 CreatedBy;
        type Repo;
        type CreatedAt;
        type Key;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type CreatedBy = Unset;
        type Repo = Unset;
        type CreatedAt = Unset;
        type Key = Unset;
    }
    ///State transition - sets the `created_by` field to Set
    pub struct SetCreatedBy<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCreatedBy<S> {}
    impl<S: State> State for SetCreatedBy<S> {
        type CreatedBy = Set<members::created_by>;
        type Repo = S::Repo;
        type CreatedAt = S::CreatedAt;
        type Key = S::Key;
    }
    ///State transition - sets the `repo` field to Set
    pub struct SetRepo<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetRepo<S> {}
    impl<S: State> State for SetRepo<S> {
        type CreatedBy = S::CreatedBy;
        type Repo = Set<members::repo>;
        type CreatedAt = S::CreatedAt;
        type Key = S::Key;
    }
    ///State transition - sets the `created_at` field to Set
    pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
    impl<S: State> State for SetCreatedAt<S> {
        type CreatedBy = S::CreatedBy;
        type Repo = S::Repo;
        type CreatedAt = Set<members::created_at>;
        type Key = S::Key;
    }
    ///State transition - sets the `key` field to Set
    pub struct SetKey<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetKey<S> {}
    impl<S: State> State for SetKey<S> {
        type CreatedBy = S::CreatedBy;
        type Repo = S::Repo;
        type CreatedAt = S::CreatedAt;
        type Key = Set<members::key>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `created_by` field
        pub struct created_by(());
        ///Marker type for the `repo` field
        pub struct repo(());
        ///Marker type for the `created_at` field
        pub struct created_at(());
        ///Marker type for the `key` field
        pub struct key(());
    }
}

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

impl<'a> Secret<'a> {
    /// Create a new builder for this type
    pub fn new() -> SecretBuilder<'a, secret_state::Empty> {
        SecretBuilder::new()
    }
}

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

impl<'a, S> SecretBuilder<'a, S>
where
    S: secret_state::State,
    S::CreatedAt: secret_state::IsUnset,
{
    /// Set the `createdAt` field (required)
    pub fn created_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> SecretBuilder<'a, secret_state::SetCreatedAt<S>> {
        self._fields.0 = Option::Some(value.into());
        SecretBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> SecretBuilder<'a, S>
where
    S: secret_state::State,
    S::CreatedBy: secret_state::IsUnset,
{
    /// Set the `createdBy` field (required)
    pub fn created_by(
        mut self,
        value: impl Into<Did<'a>>,
    ) -> SecretBuilder<'a, secret_state::SetCreatedBy<S>> {
        self._fields.1 = Option::Some(value.into());
        SecretBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> SecretBuilder<'a, S>
where
    S: secret_state::State,
    S::Key: secret_state::IsUnset,
{
    /// Set the `key` field (required)
    pub fn key(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> SecretBuilder<'a, secret_state::SetKey<S>> {
        self._fields.2 = Option::Some(value.into());
        SecretBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> SecretBuilder<'a, S>
where
    S: secret_state::State,
    S::Repo: secret_state::IsUnset,
{
    /// Set the `repo` field (required)
    pub fn repo(
        mut self,
        value: impl Into<AtUri<'a>>,
    ) -> SecretBuilder<'a, secret_state::SetRepo<S>> {
        self._fields.3 = Option::Some(value.into());
        SecretBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> SecretBuilder<'a, S>
where
    S: secret_state::State,
    S::CreatedBy: secret_state::IsSet,
    S::Repo: secret_state::IsSet,
    S::CreatedAt: secret_state::IsSet,
    S::Key: secret_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Secret<'a> {
        Secret {
            created_at: self._fields.0.unwrap(),
            created_by: self._fields.1.unwrap(),
            key: self._fields.2.unwrap(),
            repo: 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,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Secret<'a> {
        Secret {
            created_at: self._fields.0.unwrap(),
            created_by: self._fields.1.unwrap(),
            key: self._fields.2.unwrap(),
            repo: self._fields.3.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_sh_tangled_repo_listSecrets() -> 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("sh.tangled.repo.listSecrets"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcQuery(LexXrpcQuery {
                    parameters: Some(
                        LexXrpcQueryParameter::Params(LexXrpcParameters {
                            required: Some(vec![SmolStr::new_static("repo")]),
                            properties: {
                                #[allow(unused_mut)]
                                let mut map = BTreeMap::new();
                                map.insert(
                                    SmolStr::new_static("repo"),
                                    LexXrpcParametersProperty::String(LexString {
                                        format: Some(LexStringFormat::AtUri),
                                        ..Default::default()
                                    }),
                                );
                                map
                            },
                            ..Default::default()
                        }),
                    ),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("secret"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("repo"), SmolStr::new_static("key"),
                            SmolStr::new_static("createdAt"),
                            SmolStr::new_static("createdBy")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("createdAt"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("createdBy"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("key"),
                            LexObjectProperty::String(LexString {
                                min_length: Some(1usize),
                                max_length: Some(50usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("repo"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}