use crate::{
operation_handler::core::{ScimOperationRequest, ScimOperationType, ScimQuery},
resource::{TenantContext, version::ScimVersion},
};
use serde_json::Value;
impl ScimOperationRequest {
pub fn create(resource_type: impl Into<String>, data: Value) -> Self {
Self {
operation: ScimOperationType::Create,
resource_type: resource_type.into(),
resource_id: None,
data: Some(data),
query: None,
tenant_context: None,
request_id: None,
expected_version: None,
}
}
pub fn get(resource_type: impl Into<String>, resource_id: impl Into<String>) -> Self {
Self {
operation: ScimOperationType::Get,
resource_type: resource_type.into(),
resource_id: Some(resource_id.into()),
data: None,
query: None,
tenant_context: None,
request_id: None,
expected_version: None,
}
}
pub fn update(
resource_type: impl Into<String>,
resource_id: impl Into<String>,
data: Value,
) -> Self {
Self {
operation: ScimOperationType::Update,
resource_type: resource_type.into(),
resource_id: Some(resource_id.into()),
data: Some(data),
query: None,
tenant_context: None,
request_id: None,
expected_version: None,
}
}
pub fn delete(resource_type: impl Into<String>, resource_id: impl Into<String>) -> Self {
Self {
operation: ScimOperationType::Delete,
resource_type: resource_type.into(),
resource_id: Some(resource_id.into()),
data: None,
query: None,
tenant_context: None,
request_id: None,
expected_version: None,
}
}
pub fn list(resource_type: impl Into<String>) -> Self {
Self {
operation: ScimOperationType::List,
resource_type: resource_type.into(),
resource_id: None,
data: None,
query: None,
tenant_context: None,
request_id: None,
expected_version: None,
}
}
pub fn search(
resource_type: impl Into<String>,
attribute: impl Into<String>,
value: Value,
) -> Self {
Self {
operation: ScimOperationType::Search,
resource_type: resource_type.into(),
resource_id: None,
data: None,
query: Some(ScimQuery {
count: None,
start_index: None,
filter: None,
attributes: None,
excluded_attributes: None,
search_attribute: Some(attribute.into()),
search_value: Some(value),
}),
tenant_context: None,
request_id: None,
expected_version: None,
}
}
pub fn get_schemas() -> Self {
Self {
operation: ScimOperationType::GetSchemas,
resource_type: "Schema".to_string(),
resource_id: None,
data: None,
query: None,
tenant_context: None,
request_id: None,
expected_version: None,
}
}
pub fn get_schema(schema_id: impl Into<String>) -> Self {
Self {
operation: ScimOperationType::GetSchema,
resource_type: "Schema".to_string(),
resource_id: Some(schema_id.into()),
data: None,
query: None,
tenant_context: None,
request_id: None,
expected_version: None,
}
}
pub fn exists(resource_type: impl Into<String>, resource_id: impl Into<String>) -> Self {
Self {
operation: ScimOperationType::Exists,
resource_type: resource_type.into(),
resource_id: Some(resource_id.into()),
data: None,
query: None,
tenant_context: None,
request_id: None,
expected_version: None,
}
}
pub fn with_tenant(mut self, tenant_context: TenantContext) -> Self {
self.tenant_context = Some(tenant_context);
self
}
pub fn with_request_id(mut self, request_id: impl Into<String>) -> Self {
self.request_id = Some(request_id.into());
self
}
pub fn with_query(mut self, query: ScimQuery) -> Self {
self.query = Some(query);
self
}
pub fn with_expected_version(mut self, version: ScimVersion) -> Self {
self.expected_version = Some(version);
self
}
}