use thiserror::Error;
#[derive(Error, Debug, Clone)]
pub enum ResourceGroupError {
#[error("Resource not found: {code}")]
NotFound { code: String },
#[error("Resource already exists: {code}")]
TypeAlreadyExists { code: String },
#[error("Validation error: {message}")]
Validation { message: String },
#[error("Allowed parents violation: {message}")]
AllowedParentTypesViolation { message: String },
#[error("Active references exist: {message}")]
ConflictActiveReferences { message: String },
#[error("Conflict: {message}")]
Conflict { message: String },
#[error("Invalid parent type: {message}")]
InvalidParentType { message: String },
#[error("Cycle detected: {message}")]
CycleDetected { message: String },
#[error("Limit violation: {message}")]
LimitViolation { message: String },
#[error("Tenant incompatibility: {message}")]
TenantIncompatibility { message: String },
#[error("Service unavailable: {message}")]
ServiceUnavailable { message: String },
#[error("Access denied")]
AccessDenied,
#[error("Internal error")]
Internal,
}
impl ResourceGroupError {
pub fn not_found(code: impl Into<String>) -> Self {
Self::NotFound { code: code.into() }
}
pub fn type_already_exists(code: impl Into<String>) -> Self {
Self::TypeAlreadyExists { code: code.into() }
}
pub fn validation(message: impl Into<String>) -> Self {
Self::Validation {
message: message.into(),
}
}
pub fn allowed_parent_types_violation(message: impl Into<String>) -> Self {
Self::AllowedParentTypesViolation {
message: message.into(),
}
}
pub fn conflict_active_references(message: impl Into<String>) -> Self {
Self::ConflictActiveReferences {
message: message.into(),
}
}
pub fn conflict(message: impl Into<String>) -> Self {
Self::Conflict {
message: message.into(),
}
}
pub fn invalid_parent_type(message: impl Into<String>) -> Self {
Self::InvalidParentType {
message: message.into(),
}
}
pub fn cycle_detected(message: impl Into<String>) -> Self {
Self::CycleDetected {
message: message.into(),
}
}
pub fn limit_violation(message: impl Into<String>) -> Self {
Self::LimitViolation {
message: message.into(),
}
}
pub fn tenant_incompatibility(message: impl Into<String>) -> Self {
Self::TenantIncompatibility {
message: message.into(),
}
}
pub fn service_unavailable(message: impl Into<String>) -> Self {
Self::ServiceUnavailable {
message: message.into(),
}
}
#[must_use]
pub fn access_denied() -> Self {
Self::AccessDenied
}
#[must_use]
pub fn internal() -> Self {
Self::Internal
}
}