// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: com.atproto.sync.listRepos
//
// 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, Tid, Cid};
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::com_atproto::sync::list_repos;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ListRepos<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cursor: Option<CowStr<'a>>,
    ///Defaults to `500`. Min: 1. Max: 1000.
    #[serde(default = "_default_limit")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ListReposOutput<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cursor: Option<CowStr<'a>>,
    #[serde(borrow)]
    pub repos: Vec<list_repos::Repo<'a>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Repo<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub active: Option<bool>,
    #[serde(borrow)]
    pub did: Did<'a>,
    ///Current repo commit CID
    #[serde(borrow)]
    pub head: Cid<'a>,
    pub rev: Tid,
    ///If active=false, this optional field indicates a possible reason for why the account is not active. If active=false and no status is supplied, then the host makes no claim for why the repository is no longer being hosted.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub status: Option<RepoStatus<'a>>,
}

/// If active=false, this optional field indicates a possible reason for why the account is not active. If active=false and no status is supplied, then the host makes no claim for why the repository is no longer being hosted.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum RepoStatus<'a> {
    Takendown,
    Suspended,
    Deleted,
    Deactivated,
    Desynchronized,
    Throttled,
    Other(CowStr<'a>),
}

impl<'a> RepoStatus<'a> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Takendown => "takendown",
            Self::Suspended => "suspended",
            Self::Deleted => "deleted",
            Self::Deactivated => "deactivated",
            Self::Desynchronized => "desynchronized",
            Self::Throttled => "throttled",
            Self::Other(s) => s.as_ref(),
        }
    }
}

impl<'a> From<&'a str> for RepoStatus<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "takendown" => Self::Takendown,
            "suspended" => Self::Suspended,
            "deleted" => Self::Deleted,
            "deactivated" => Self::Deactivated,
            "desynchronized" => Self::Desynchronized,
            "throttled" => Self::Throttled,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for RepoStatus<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "takendown" => Self::Takendown,
            "suspended" => Self::Suspended,
            "deleted" => Self::Deleted,
            "deactivated" => Self::Deactivated,
            "desynchronized" => Self::Desynchronized,
            "throttled" => Self::Throttled,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> core::fmt::Display for RepoStatus<'a> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

impl<'a> AsRef<str> for RepoStatus<'a> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl<'a> serde::Serialize for RepoStatus<'a> {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de, 'a> serde::Deserialize<'de> for RepoStatus<'a>
where
    'de: 'a,
{
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = <&'de str>::deserialize(deserializer)?;
        Ok(Self::from(s))
    }
}

impl<'a> Default for RepoStatus<'a> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl jacquard_common::IntoStatic for RepoStatus<'_> {
    type Output = RepoStatus<'static>;
    fn into_static(self) -> Self::Output {
        match self {
            RepoStatus::Takendown => RepoStatus::Takendown,
            RepoStatus::Suspended => RepoStatus::Suspended,
            RepoStatus::Deleted => RepoStatus::Deleted,
            RepoStatus::Deactivated => RepoStatus::Deactivated,
            RepoStatus::Desynchronized => RepoStatus::Desynchronized,
            RepoStatus::Throttled => RepoStatus::Throttled,
            RepoStatus::Other(v) => RepoStatus::Other(v.into_static()),
        }
    }
}

/// Response type for com.atproto.sync.listRepos
pub struct ListReposResponse;
impl jacquard_common::xrpc::XrpcResp for ListReposResponse {
    const NSID: &'static str = "com.atproto.sync.listRepos";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = ListReposOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for ListRepos<'a> {
    const NSID: &'static str = "com.atproto.sync.listRepos";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = ListReposResponse;
}

/// Endpoint type for com.atproto.sync.listRepos
pub struct ListReposRequest;
impl jacquard_common::xrpc::XrpcEndpoint for ListReposRequest {
    const PATH: &'static str = "/xrpc/com.atproto.sync.listRepos";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<'de> = ListRepos<'de>;
    type Response = ListReposResponse;
}

impl<'a> LexiconSchema for Repo<'a> {
    fn nsid() -> &'static str {
        "com.atproto.sync.listRepos"
    }
    fn def_name() -> &'static str {
        "repo"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_atproto_sync_listRepos()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

fn _default_limit() -> Option<i64> {
    Some(500i64)
}

pub mod list_repos_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 {}
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {}
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {}
}

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

impl<'a> ListRepos<'a> {
    /// Create a new builder for this type
    pub fn new() -> ListReposBuilder<'a, list_repos_state::Empty> {
        ListReposBuilder::new()
    }
}

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

impl<'a, S: list_repos_state::State> ListReposBuilder<'a, S> {
    /// Set the `cursor` field (optional)
    pub fn cursor(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `cursor` field to an Option value (optional)
    pub fn maybe_cursor(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<'a, S: list_repos_state::State> ListReposBuilder<'a, S> {
    /// Set the `limit` field (optional)
    pub fn limit(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `limit` field to an Option value (optional)
    pub fn maybe_limit(mut self, value: Option<i64>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<'a, S> ListReposBuilder<'a, S>
where
    S: list_repos_state::State,
{
    /// Build the final struct
    pub fn build(self) -> ListRepos<'a> {
        ListRepos {
            cursor: self._fields.0,
            limit: self._fields.1,
        }
    }
}

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

/// Builder for constructing an instance of this type
pub struct RepoBuilder<'a, S: repo_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<bool>,
        Option<Did<'a>>,
        Option<Cid<'a>>,
        Option<Tid>,
        Option<RepoStatus<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> Repo<'a> {
    /// Create a new builder for this type
    pub fn new() -> RepoBuilder<'a, repo_state::Empty> {
        RepoBuilder::new()
    }
}

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

impl<'a, S: repo_state::State> RepoBuilder<'a, S> {
    /// Set the `active` field (optional)
    pub fn active(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `active` field to an Option value (optional)
    pub fn maybe_active(mut self, value: Option<bool>) -> Self {
        self._fields.0 = value;
        self
    }
}

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

impl<'a, S> RepoBuilder<'a, S>
where
    S: repo_state::State,
    S::Head: repo_state::IsUnset,
{
    /// Set the `head` field (required)
    pub fn head(
        mut self,
        value: impl Into<Cid<'a>>,
    ) -> RepoBuilder<'a, repo_state::SetHead<S>> {
        self._fields.2 = Option::Some(value.into());
        RepoBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> RepoBuilder<'a, S>
where
    S: repo_state::State,
    S::Rev: repo_state::IsUnset,
{
    /// Set the `rev` field (required)
    pub fn rev(
        mut self,
        value: impl Into<Tid>,
    ) -> RepoBuilder<'a, repo_state::SetRev<S>> {
        self._fields.3 = Option::Some(value.into());
        RepoBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: repo_state::State> RepoBuilder<'a, S> {
    /// Set the `status` field (optional)
    pub fn status(mut self, value: impl Into<Option<RepoStatus<'a>>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `status` field to an Option value (optional)
    pub fn maybe_status(mut self, value: Option<RepoStatus<'a>>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<'a, S> RepoBuilder<'a, S>
where
    S: repo_state::State,
    S::Rev: repo_state::IsSet,
    S::Did: repo_state::IsSet,
    S::Head: repo_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Repo<'a> {
        Repo {
            active: self._fields.0,
            did: self._fields.1.unwrap(),
            head: self._fields.2.unwrap(),
            rev: self._fields.3.unwrap(),
            status: self._fields.4,
            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>,
        >,
    ) -> Repo<'a> {
        Repo {
            active: self._fields.0,
            did: self._fields.1.unwrap(),
            head: self._fields.2.unwrap(),
            rev: self._fields.3.unwrap(),
            status: self._fields.4,
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_com_atproto_sync_listRepos() -> 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("com.atproto.sync.listRepos"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcQuery(LexXrpcQuery {
                    parameters: Some(
                        LexXrpcQueryParameter::Params(LexXrpcParameters {
                            properties: {
                                #[allow(unused_mut)]
                                let mut map = BTreeMap::new();
                                map.insert(
                                    SmolStr::new_static("cursor"),
                                    LexXrpcParametersProperty::String(LexString {
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("limit"),
                                    LexXrpcParametersProperty::Integer(LexInteger {
                                        ..Default::default()
                                    }),
                                );
                                map
                            },
                            ..Default::default()
                        }),
                    ),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("repo"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("did"), SmolStr::new_static("head"),
                            SmolStr::new_static("rev")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("active"),
                            LexObjectProperty::Boolean(LexBoolean {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("did"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("head"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Current repo commit CID"),
                                ),
                                format: Some(LexStringFormat::Cid),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("rev"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Tid),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("status"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "If active=false, this optional field indicates a possible reason for why the account is not active. If active=false and no status is supplied, then the host makes no claim for why the repository is no longer being hosted.",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}