// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: com.atproto.sync.getRepoStatus
//
// 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;
use jacquard_common::types::string::{Did, Tid};
use jacquard_derive::{IntoStatic, lexicon, open_union};
use serde::{Serialize, Deserialize};

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


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetRepoStatusOutput<'a> {
    pub active: bool,
    #[serde(borrow)]
    pub did: Did<'a>,
    ///Optional field, the current rev of the repo, if active=true
    #[serde(skip_serializing_if = "Option::is_none")]
    pub rev: Option<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<GetRepoStatusOutputStatus<'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 GetRepoStatusOutputStatus<'a> {
    Takendown,
    Suspended,
    Deleted,
    Deactivated,
    Desynchronized,
    Throttled,
    Other(CowStr<'a>),
}

impl<'a> GetRepoStatusOutputStatus<'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 GetRepoStatusOutputStatus<'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 GetRepoStatusOutputStatus<'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 GetRepoStatusOutputStatus<'a> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

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

impl<'a> serde::Serialize for GetRepoStatusOutputStatus<'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 GetRepoStatusOutputStatus<'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 GetRepoStatusOutputStatus<'a> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

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


#[open_union]
#[derive(
    Serialize,
    Deserialize,
    Debug,
    Clone,
    PartialEq,
    Eq,
    thiserror::Error,
    miette::Diagnostic,
    IntoStatic
)]

#[serde(tag = "error", content = "message")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum GetRepoStatusError<'a> {
    #[serde(rename = "RepoNotFound")]
    RepoNotFound(Option<CowStr<'a>>),
}

impl core::fmt::Display for GetRepoStatusError<'_> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::RepoNotFound(msg) => {
                write!(f, "RepoNotFound")?;
                if let Some(msg) = msg {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
            Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
        }
    }
}

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

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

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

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

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

impl<'a> GetRepoStatus<'a> {
    /// Create a new builder for this type
    pub fn new() -> GetRepoStatusBuilder<'a, get_repo_status_state::Empty> {
        GetRepoStatusBuilder::new()
    }
}

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

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

impl<'a, S> GetRepoStatusBuilder<'a, S>
where
    S: get_repo_status_state::State,
    S::Did: get_repo_status_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> GetRepoStatus<'a> {
        GetRepoStatus {
            did: self._fields.0.unwrap(),
        }
    }
}