use thiserror::Error;
#[derive(Debug, Clone, Error)]
pub enum InMemoryError {
#[error("Resource not found: {resource_type} with id '{id}' in tenant '{tenant_id}'")]
ResourceNotFound {
resource_type: String,
id: String,
tenant_id: String,
},
#[error("Duplicate attribute '{attribute}' with value '{value}' for {resource_type} in tenant '{tenant_id}'")]
DuplicateAttribute {
resource_type: String,
attribute: String,
value: String,
tenant_id: String,
},
#[error("Invalid resource data: {message}")]
InvalidData {
message: String,
},
#[error("Query error: {message}")]
QueryError {
message: String,
},
#[error("Internal error: {message}")]
Internal {
message: String,
},
#[error("Invalid input: {message}")]
InvalidInput {
message: String,
},
#[error("Resource not found: {resource_type} with id '{id}'")]
NotFound {
resource_type: String,
id: String,
},
#[error("Precondition failed: {message}")]
PreconditionFailed {
message: String,
},
#[error("Duplicate resource: {resource_type} with userName '{username}' already exists in tenant '{tenant_id}'")]
DuplicateUserName {
resource_type: String,
username: String,
tenant_id: String,
},
#[error("Patch operation failed: {message}")]
PatchOperationFailed {
message: String,
},
#[error("Version conflict: {conflict}")]
VersionConflict {
#[from]
conflict: crate::resource::version::VersionConflict,
},
}
#[derive(Debug, Clone)]
pub struct InMemoryStats {
pub tenant_count: usize,
pub total_resources: usize,
pub resource_type_count: usize,
pub resource_types: Vec<String>,
}
impl InMemoryStats {
pub fn new() -> Self {
Self {
tenant_count: 0,
total_resources: 0,
resource_type_count: 0,
resource_types: Vec::new(),
}
}
pub fn is_empty(&self) -> bool {
self.total_resources == 0
}
}
impl Default for InMemoryStats {
fn default() -> Self {
Self::new()
}
}