1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
//! Built-in constraint implementations for data validation.
//!
//! This module provides a comprehensive collection of constraints for validating
//! data quality across various dimensions. Each constraint implements the
//! [`Constraint`](crate::core::Constraint) trait and can be used within a
//! [`Check`](crate::core::Check).
//!
//! ## Unified API Overview
//!
//! Term uses a **unified constraint system** that consolidates similar validation
//! types into powerful, flexible constraints. This approach:
//!
//! - **Reduces API surface** while increasing functionality
//! - **Improves performance** through query optimization
//! - **Provides consistency** across different validation types
//!
//! ### Core Unified Constraints
//!
//! 1. **[`CompletenessConstraint`]** - Handles all completeness validations
//! - Single column: `complete()`, `with_threshold()`
//! - Multiple columns: `with_operator()` for AND/OR logic
//! - Complex patterns: `with_options()` for advanced scenarios
//!
//! 2. **[`UniquenessConstraint`]** - Covers uniqueness-related checks
//! - Full uniqueness: `full_uniqueness()`
//! - Uniqueness ratio: `unique_value_ratio()`
//! - Distinctness: `distinctness()`
//! - Primary key: `primary_key()`
//!
//! 3. **[`StatisticalConstraint`]** - All statistical validations
//! - Basic stats: `min()`, `max()`, `mean()`, `sum()`
//! - Advanced stats: `standard_deviation()`, `variance()`
//! - Quantiles: `median()`, `percentile()`
//!
//! 4. **[`FormatConstraint`]** - Pattern and format validation
//! - Regex patterns: `regex()`
//! - Email validation: `email()`
//! - URL validation: `url()`
//! - Credit card detection: `credit_card()`
//!
//! 5. **[`LengthConstraint`]** - String length validations
//! - Minimum length: `min()`
//! - Maximum length: `max()`
//! - Exact length: `exactly()`
//! - Range: `between()`
//!
//! ## Usage Examples
//!
//! ### Basic Validation Suite
//!
//! ```rust
//! use term_guard::prelude::*;
//! use term_guard::core::{Check, ValidationSuite};
//! use term_guard::constraints::{CompletenessConstraint, UniquenessConstraint, StatisticalConstraint, StatisticType, Assertion};
//!
//! # async fn example() -> Result<()> {
//! let suite = ValidationSuite::builder("data_quality")
//! .check(
//! Check::builder("completeness")
//! .constraint(CompletenessConstraint::complete("id"))
//! .constraint(CompletenessConstraint::with_threshold("email", 0.95))
//! .build()
//! )
//! .check(
//! Check::builder("uniqueness")
//! .constraint(UniquenessConstraint::primary_key(vec!["id"]).unwrap())
//! .constraint(UniquenessConstraint::unique_value_ratio(vec!["email"], Assertion::GreaterThan(0.98)).unwrap())
//! .build()
//! )
//! .check(
//! Check::builder("statistics")
//! .constraint(StatisticalConstraint::new("age", StatisticType::Min, Assertion::GreaterThanOrEqual(0.0)).unwrap())
//! .constraint(StatisticalConstraint::new("age", StatisticType::Max, Assertion::LessThan(150.0)).unwrap())
//! .build()
//! )
//! .build();
//! # Ok(())
//! # }
//! ```
//!
//! ### Using the Fluent API
//!
//! ```rust
//! use term_guard::prelude::*;
//! use term_guard::core::{Check, builder_extensions::*};
//! use term_guard::constraints::{Assertion, FormatOptions, FormatType};
//!
//! # async fn example() -> Result<()> {
//! let check = Check::builder("user_validation")
//! // Completeness checks
//! .completeness("user_id", CompletenessOptions::full().into_constraint_options())
//! .completeness("email", CompletenessOptions::threshold(0.99).into_constraint_options())
//!
//! // Statistical checks
//! .statistics(
//! "age",
//! StatisticalOptions::new()
//! .min(Assertion::GreaterThanOrEqual(13.0))
//! .max(Assertion::LessThanOrEqual(120.0))
//! .mean(Assertion::Between(25.0, 65.0))
//! )?
//!
//! // Format validation
//! .has_format("email", FormatType::Email, 0.99, FormatOptions::default())
//!
//! .build();
//! # Ok(())
//! # }
//! ```
//!
//! ### Custom Constraints
//!
//! For business-specific rules, use [`CustomSqlConstraint`]:
//!
//! ```rust
//! use term_guard::constraints::CustomSqlConstraint;
//!
//! # fn example() -> term_guard::prelude::Result<()> {
//! let constraint = CustomSqlConstraint::new(
//! "discount_amount <= total_amount * 0.5",
//! Some("Discount cannot exceed 50% of total")
//! )?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Performance Optimization
//!
//! The unified constraint system enables powerful optimizations:
//!
//! ```rust
//! use term_guard::prelude::*;
//! use term_guard::core::{Check, ValidationSuite};
//! use term_guard::constraints::{StatisticalConstraint, StatisticType, Assertion};
//!
//! # async fn example() -> Result<()> {
//! // These constraints will be combined into a single query
//! let check = Check::builder("optimized")
//! .constraint(StatisticalConstraint::new("price", StatisticType::Min, Assertion::GreaterThan(0.0)).unwrap())
//! .constraint(StatisticalConstraint::new("price", StatisticType::Max, Assertion::LessThan(1000.0)).unwrap())
//! .constraint(StatisticalConstraint::new("price", StatisticType::Mean, Assertion::Between(50.0, 200.0)).unwrap())
//! .build();
//!
//! // Enable optimizer for best performance
//! let suite = ValidationSuite::builder("suite")
//! .with_optimizer(true)
//! .check(check)
//! .build();
//! # Ok(())
//! # }
//! ```
//!
//! ## Constraint Categories
//!
//! ### Data Completeness
//! - [`CompletenessConstraint`] - Null value validation
//! - [`SizeConstraint`] - Row count validation
//!
//! ### Data Uniqueness
//! - [`UniquenessConstraint`] - Duplicate detection
//! - [`ApproxCountDistinctConstraint`] - Approximate distinct counts
//!
//! ### Statistical Analysis
//! - [`StatisticalConstraint`] - Statistical measures
//! - [`QuantileConstraint`] - Percentile analysis
//! - [`CorrelationConstraint`] - Column relationships
//! - [`HistogramConstraint`] - Value distribution
//!
//! ### Pattern & Format
//! - [`FormatConstraint`] - Pattern matching
//! - [`LengthConstraint`] - String length validation
//! - [`DataTypeConstraint`] - Type validation
//!
//! ### Custom Rules
//! - [`CustomSqlConstraint`] - SQL expressions
//! - [`ColumnCountConstraint`] - Schema validation
//!
//! ## Best Practices
//!
//! 1. **Use unified constraints** - They provide better performance and consistency
//! 2. **Group related checks** - Organize constraints into logical checks
//! 3. **Enable optimization** - Use `with_optimizer(true)` for large datasets
//! 4. **Set appropriate thresholds** - Not all data needs 100% compliance
//! 5. **Monitor performance** - Use telemetry features for production systems
// Module declarations - only non-deprecated modules
// Public exports
pub use ApproxCountDistinctConstraint;
pub use Assertion;
pub use ColumnCountConstraint;
pub use CompletenessConstraint;
pub use ;
pub use CrossTableSumConstraint;
pub use CustomSqlConstraint;
pub use ;
pub use ForeignKeyConstraint;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use SizeConstraint;
pub use ;
pub use ;
pub use ;
pub use ContainmentConstraint;