// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: io.atcr.hold.getQuota
//
// 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, BosStr, DefaultStr, FromStaticStr};
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::string::Did;
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, open_union};
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GetQuota<S: BosStr = DefaultStr> {
    pub user_did: Did<S>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GetQuotaOutput<S: BosStr = DefaultStr> {
    ///Storage limit in bytes (absent if unlimited)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
    ///Quota tier name (e.g., 'deckhand', 'bosun', 'quartermaster')
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tier: Option<S>,
    ///Total size in bytes of unique blobs
    pub total_size: i64,
    ///Number of unique blob digests
    pub unique_blobs: i64,
    ///DID of the user
    pub user_did: Did<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


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

#[serde(tag = "error", content = "message")]
pub enum GetQuotaError {
    #[serde(rename = "InvalidUserDid")]
    InvalidUserDid(Option<SmolStr>),
    /// Catch-all for unknown error codes.
    #[serde(untagged)]
    Other { error: SmolStr, message: Option<SmolStr> },
}

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

/** Response marker for the `io.atcr.hold.getQuota` query.

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `GetQuotaOutput<S>` for this endpoint.*/
pub struct GetQuotaResponse;
impl jacquard_common::xrpc::XrpcResp for GetQuotaResponse {
    const NSID: &'static str = "io.atcr.hold.getQuota";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = GetQuotaOutput<S>;
    type Err = GetQuotaError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for GetQuota<S> {
    const NSID: &'static str = "io.atcr.hold.getQuota";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = GetQuotaResponse;
}

/** Endpoint marker for the `io.atcr.hold.getQuota` query.

Path: `/xrpc/io.atcr.hold.getQuota`. The request payload type is `GetQuota<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
pub struct GetQuotaRequest;
impl jacquard_common::xrpc::XrpcEndpoint for GetQuotaRequest {
    const PATH: &'static str = "/xrpc/io.atcr.hold.getQuota";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<S: BosStr> = GetQuota<S>;
    type Response = GetQuotaResponse;
}

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

/// Builder for constructing an instance of this type.
pub struct GetQuotaBuilder<St: get_quota_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<Did<S>>,),
    _type: PhantomData<fn() -> S>,
}

impl GetQuota<DefaultStr> {
    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
    pub fn new() -> GetQuotaBuilder<get_quota_state::Empty, DefaultStr> {
        GetQuotaBuilder::new()
    }
}

impl<S: BosStr> GetQuota<S> {
    /// Create a new builder for this type
    pub fn builder() -> GetQuotaBuilder<get_quota_state::Empty, S> {
        GetQuotaBuilder::builder()
    }
}

impl GetQuotaBuilder<get_quota_state::Empty, DefaultStr> {
    /// Create a new builder with all fields unset, using the default string type, if needed
    pub fn new() -> Self {
        GetQuotaBuilder {
            _state: PhantomData,
            _fields: (None,),
            _type: PhantomData,
        }
    }
}

impl<S: BosStr> GetQuotaBuilder<get_quota_state::Empty, S> {
    /// Create a new builder with all fields unset
    pub fn builder() -> Self {
        GetQuotaBuilder {
            _state: PhantomData,
            _fields: (None,),
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> GetQuotaBuilder<St, S>
where
    St: get_quota_state::State,
    St::UserDid: get_quota_state::IsUnset,
{
    /// Set the `userDid` field (required)
    pub fn user_did(
        mut self,
        value: impl Into<Did<S>>,
    ) -> GetQuotaBuilder<get_quota_state::SetUserDid<St>, S> {
        self._fields.0 = Option::Some(value.into());
        GetQuotaBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> GetQuotaBuilder<St, S>
where
    St: get_quota_state::State,
    St::UserDid: get_quota_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> GetQuota<S> {
        GetQuota {
            user_did: self._fields.0.unwrap(),
        }
    }
}