// @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;
use jacquard_common::types::string::Did;
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 GetQuota<'a> {
    #[serde(borrow)]
    pub user_did: Did<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetQuotaOutput<'a> {
    ///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")]
    #[serde(borrow)]
    pub tier: Option<CowStr<'a>>,
    ///Total size in bytes of unique blobs
    pub total_size: i64,
    ///Number of unique blob digests
    pub unique_blobs: i64,
    ///DID of the user
    #[serde(borrow)]
    pub user_did: Did<'a>,
}


#[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 GetQuotaError<'a> {
    #[serde(rename = "InvalidUserDid")]
    InvalidUserDid(Option<CowStr<'a>>),
}

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::Unknown(err) => write!(f, "Unknown error: {:?}", err),
        }
    }
}

/// Response type for io.atcr.hold.getQuota
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<'de> = GetQuotaOutput<'de>;
    type Err<'de> = GetQuotaError<'de>;
}

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

/// Endpoint type for io.atcr.hold.getQuota
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<'de> = GetQuota<'de>;
    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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetUserDid<S> {}
    impl<S: State> State for SetUserDid<S> {
        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<'a, S: get_quota_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<Did<'a>>,),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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