Skip to main content

stateset_embedded/
integration_field_mappings.rs

1//! Integration field-mapping operations (field-path mappings).
2
3use stateset_core::{
4    CreateIntegrationFieldMapping, IntegrationFieldMapping, IntegrationFieldMappingFilter,
5    IntegrationFieldMappingId, Result, UpdateIntegrationFieldMapping,
6};
7use stateset_db::{Database, DatabaseCapability};
8use std::sync::Arc;
9
10/// Integration field-mapping operations.
11pub struct IntegrationFieldMappings {
12    db: Arc<dyn Database>,
13}
14
15impl std::fmt::Debug for IntegrationFieldMappings {
16    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
17        f.debug_struct("IntegrationFieldMappings").finish_non_exhaustive()
18    }
19}
20
21impl IntegrationFieldMappings {
22    pub(crate) fn new(db: Arc<dyn Database>) -> Self {
23        Self { db }
24    }
25
26    /// Whether integration field mappings are supported by the active backend.
27    #[must_use]
28    pub fn is_supported(&self) -> bool {
29        self.db.supports_capability(DatabaseCapability::IntegrationFieldMappings)
30    }
31
32    fn ensure(&self) -> Result<()> {
33        self.db.ensure_capability(DatabaseCapability::IntegrationFieldMappings)
34    }
35
36    /// Create a field mapping.
37    pub fn create(&self, input: CreateIntegrationFieldMapping) -> Result<IntegrationFieldMapping> {
38        self.ensure()?;
39        self.db.integration_field_mappings().create(input)
40    }
41
42    /// Get a field mapping by ID.
43    pub fn get(&self, id: IntegrationFieldMappingId) -> Result<Option<IntegrationFieldMapping>> {
44        self.ensure()?;
45        self.db.integration_field_mappings().get(id)
46    }
47
48    /// Update a field mapping.
49    pub fn update(
50        &self,
51        id: IntegrationFieldMappingId,
52        input: UpdateIntegrationFieldMapping,
53    ) -> Result<IntegrationFieldMapping> {
54        self.ensure()?;
55        self.db.integration_field_mappings().update(id, input)
56    }
57
58    /// List field mappings with optional filtering.
59    pub fn list(
60        &self,
61        filter: IntegrationFieldMappingFilter,
62    ) -> Result<Vec<IntegrationFieldMapping>> {
63        self.ensure()?;
64        self.db.integration_field_mappings().list(filter)
65    }
66
67    /// Delete a field mapping.
68    pub fn delete(&self, id: IntegrationFieldMappingId) -> Result<()> {
69        self.ensure()?;
70        self.db.integration_field_mappings().delete(id)
71    }
72
73    /// Bulk create field mappings.
74    pub fn bulk_create(&self, items: Vec<CreateIntegrationFieldMapping>) -> Result<u64> {
75        self.ensure()?;
76        self.db.integration_field_mappings().bulk_create(items)
77    }
78
79    /// Bulk delete field mappings by ID.
80    pub fn bulk_delete(&self, ids: Vec<IntegrationFieldMappingId>) -> Result<u64> {
81        self.ensure()?;
82        self.db.integration_field_mappings().bulk_delete(ids)
83    }
84
85    /// List the distinct mapping groups for an integration account.
86    pub fn distinct_groups(&self, integration_account: &str) -> Result<Vec<String>> {
87        self.ensure()?;
88        self.db.integration_field_mappings().distinct_groups(integration_account)
89    }
90}