use spacedb_access::DenyReason;
use thiserror::Error;
use crate::schema::CrdtType;
pub type SdkResult<T> = Result<T, SdkError>;
#[derive(Debug, Error)]
pub enum SdkError {
#[error("access denied: {0:?}")]
Denied(DenyReason),
#[error("over budget: op costs {cost} micro-$MATA, {remaining} remaining")]
OverBudget { cost: u64, remaining: u64 },
#[error("field '{field}' is a {found}, not a {expected}")]
WrongType {
field: String,
expected: CrdtType,
found: CrdtType,
},
#[error("field '{0}' is strong-tier; use claim_unique")]
StrongFieldNeedsClaim(String),
#[error("unknown collection '{0}'")]
UnknownCollection(String),
#[error("unknown field '{field}' in collection '{collection}'")]
UnknownField { collection: String, field: String },
#[error("crdt error: {0}")]
Crdt(String),
#[error("auth error: {0}")]
Auth(String),
}
impl std::fmt::Display for CrdtType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.name())
}
}