datasynth-generators 3.1.0

50+ data generators covering GL, P2P, O2C, S2C, HR, manufacturing, audit, tax, treasury, and ESG
Documentation
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
//! Entity-aware anomaly injection.
//!
//! Provides rules for injecting anomalies based on entity characteristics,
//! such as vendor tenure, employee experience, and account types.

use chrono::NaiveDate;
use rand::{Rng, RngExt};
use rust_decimal::Decimal;
use rust_decimal_macros::dec;
use serde::{Deserialize, Serialize};

use datasynth_core::models::{AnomalyType, ErrorType, FraudType, ProcessIssueType};

/// Configuration for entity-aware anomaly injection.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EntityAwareConfig {
    /// Enable entity-aware injection.
    pub enabled: bool,
    /// Vendor-specific rules.
    pub vendor_rules: VendorAnomalyRules,
    /// Employee-specific rules.
    pub employee_rules: EmployeeAnomalyRules,
    /// Account-specific rules.
    pub account_rules: AccountAnomalyRules,
}

impl Default for EntityAwareConfig {
    fn default() -> Self {
        Self {
            enabled: true,
            vendor_rules: VendorAnomalyRules::default(),
            employee_rules: EmployeeAnomalyRules::default(),
            account_rules: AccountAnomalyRules::default(),
        }
    }
}

/// Rules for vendor-specific anomaly patterns.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VendorAnomalyRules {
    /// Threshold for "new" vendor in days.
    pub new_vendor_threshold_days: u32,
    /// Error rate multiplier for new vendors.
    pub new_vendor_error_multiplier: f64,
    /// Anomaly types more common with new vendors.
    pub new_vendor_error_types: Vec<AnomalyType>,
    /// Threshold for "strategic" vendor by total spend.
    pub strategic_vendor_spend_threshold: Decimal,
    /// Anomaly types for strategic vendors (typically fraud).
    pub strategic_vendor_types: Vec<AnomalyType>,
    /// International vendor FX/tax error types.
    pub international_error_types: Vec<AnomalyType>,
    /// Dormant vendor threshold in days.
    pub dormant_vendor_threshold_days: u32,
    /// Error multiplier for dormant vendor reactivation.
    pub dormant_reactivation_multiplier: f64,
}

impl Default for VendorAnomalyRules {
    fn default() -> Self {
        Self {
            new_vendor_threshold_days: 90,
            new_vendor_error_multiplier: 2.5,
            new_vendor_error_types: vec![
                AnomalyType::Error(ErrorType::MissingField),
                AnomalyType::Error(ErrorType::MisclassifiedAccount),
                AnomalyType::Error(ErrorType::MissingField),
                AnomalyType::ProcessIssue(ProcessIssueType::MissingDocumentation),
            ],
            strategic_vendor_spend_threshold: dec!(1000000),
            strategic_vendor_types: vec![
                AnomalyType::Fraud(FraudType::Kickback),
                AnomalyType::Fraud(FraudType::InvoiceManipulation),
                AnomalyType::Fraud(FraudType::SplitTransaction),
            ],
            international_error_types: vec![
                AnomalyType::Error(ErrorType::CurrencyError),
                AnomalyType::Error(ErrorType::TaxCalculationError),
                AnomalyType::Error(ErrorType::WrongPeriod),
            ],
            dormant_vendor_threshold_days: 180,
            dormant_reactivation_multiplier: 1.8,
        }
    }
}

impl VendorAnomalyRules {
    /// Checks if a vendor is considered "new".
    pub fn is_new_vendor(&self, creation_date: NaiveDate, current_date: NaiveDate) -> bool {
        let days = (current_date - creation_date).num_days();
        days >= 0 && days < self.new_vendor_threshold_days as i64
    }

    /// Checks if a vendor is "dormant" (no activity for threshold period).
    pub fn is_dormant_vendor(&self, last_activity: NaiveDate, current_date: NaiveDate) -> bool {
        let days = (current_date - last_activity).num_days();
        days >= self.dormant_vendor_threshold_days as i64
    }

    /// Checks if a vendor is "strategic" based on total spend.
    pub fn is_strategic_vendor(&self, total_spend: Decimal) -> bool {
        total_spend >= self.strategic_vendor_spend_threshold
    }

    /// Gets the error rate multiplier for a vendor.
    pub fn get_multiplier(&self, context: &VendorContext) -> f64 {
        let mut multiplier = 1.0;

        if context.is_new {
            multiplier *= self.new_vendor_error_multiplier;
        }

        if context.is_dormant_reactivation {
            multiplier *= self.dormant_reactivation_multiplier;
        }

        multiplier
    }

    /// Gets applicable anomaly types for a vendor context.
    pub fn get_applicable_types(&self, context: &VendorContext) -> Vec<AnomalyType> {
        let mut types = Vec::new();

        if context.is_new {
            types.extend(self.new_vendor_error_types.clone());
        }

        if context.is_strategic {
            types.extend(self.strategic_vendor_types.clone());
        }

        if context.is_international {
            types.extend(self.international_error_types.clone());
        }

        types
    }
}

/// Context information about a vendor.
#[derive(Debug, Clone, Default)]
pub struct VendorContext {
    /// Vendor ID.
    pub vendor_id: String,
    /// Whether vendor is new (< threshold days).
    pub is_new: bool,
    /// Whether vendor is strategic (high spend).
    pub is_strategic: bool,
    /// Whether vendor is international.
    pub is_international: bool,
    /// Whether this is a dormant vendor reactivation.
    pub is_dormant_reactivation: bool,
    /// Total spend with this vendor.
    pub total_spend: Decimal,
    /// Days since vendor creation.
    pub days_since_creation: i64,
    /// Days since last activity.
    pub days_since_last_activity: i64,
}

/// Rules for employee-specific anomaly patterns.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EmployeeAnomalyRules {
    /// Threshold for "new" employee in days.
    pub new_employee_threshold_days: u32,
    /// Error rate for new employees.
    pub new_employee_error_rate: f64,
    /// Transaction volume threshold for fatigue.
    pub volume_fatigue_threshold: u32,
    /// Error multiplier when volume exceeds threshold.
    pub volume_fatigue_multiplier: f64,
    /// Error multiplier when covering for absent approver.
    pub coverage_error_multiplier: f64,
    /// Overtime hours threshold for error spike.
    pub overtime_hours_threshold: f64,
    /// Error multiplier during overtime.
    pub overtime_error_multiplier: f64,
    /// Error types more common with new employees.
    pub new_employee_error_types: Vec<AnomalyType>,
    /// Error types from fatigue.
    pub fatigue_error_types: Vec<AnomalyType>,
}

impl Default for EmployeeAnomalyRules {
    fn default() -> Self {
        Self {
            new_employee_threshold_days: 180,
            new_employee_error_rate: 0.05,
            volume_fatigue_threshold: 50,
            volume_fatigue_multiplier: 1.5,
            coverage_error_multiplier: 1.3,
            overtime_hours_threshold: 45.0,
            overtime_error_multiplier: 1.4,
            new_employee_error_types: vec![
                AnomalyType::Error(ErrorType::MisclassifiedAccount),
                AnomalyType::Error(ErrorType::WrongPeriod),
                AnomalyType::Error(ErrorType::MissingField),
                AnomalyType::ProcessIssue(ProcessIssueType::IncompleteApprovalChain),
            ],
            fatigue_error_types: vec![
                AnomalyType::Error(ErrorType::DuplicateEntry),
                AnomalyType::Error(ErrorType::TransposedDigits),
                AnomalyType::Error(ErrorType::ReversedAmount),
                AnomalyType::ProcessIssue(ProcessIssueType::SkippedApproval),
            ],
        }
    }
}

impl EmployeeAnomalyRules {
    /// Checks if an employee is considered "new".
    pub fn is_new_employee(&self, hire_date: NaiveDate, current_date: NaiveDate) -> bool {
        let days = (current_date - hire_date).num_days();
        days >= 0 && days < self.new_employee_threshold_days as i64
    }

    /// Checks if employee is experiencing volume fatigue.
    pub fn is_volume_fatigue(&self, daily_transaction_count: u32) -> bool {
        daily_transaction_count > self.volume_fatigue_threshold
    }

    /// Checks if employee is in overtime.
    pub fn is_overtime(&self, weekly_hours: f64) -> bool {
        weekly_hours > self.overtime_hours_threshold
    }

    /// Gets the error rate multiplier for an employee.
    pub fn get_multiplier(&self, context: &EmployeeContext) -> f64 {
        let mut multiplier = 1.0;

        if context.is_new {
            multiplier *= 1.0 + self.new_employee_error_rate * 10.0;
        }

        if context.is_volume_fatigued {
            multiplier *= self.volume_fatigue_multiplier;
        }

        if context.is_covering {
            multiplier *= self.coverage_error_multiplier;
        }

        if context.is_overtime {
            multiplier *= self.overtime_error_multiplier;
        }

        multiplier
    }

    /// Gets applicable anomaly types for an employee context.
    pub fn get_applicable_types(&self, context: &EmployeeContext) -> Vec<AnomalyType> {
        let mut types = Vec::new();

        if context.is_new {
            types.extend(self.new_employee_error_types.clone());
        }

        if context.is_volume_fatigued || context.is_overtime {
            types.extend(self.fatigue_error_types.clone());
        }

        types
    }
}

/// Context information about an employee.
#[derive(Debug, Clone, Default)]
pub struct EmployeeContext {
    /// Employee ID.
    pub employee_id: String,
    /// Whether employee is new (< threshold days).
    pub is_new: bool,
    /// Whether employee is experiencing volume fatigue.
    pub is_volume_fatigued: bool,
    /// Whether employee is covering for an absent approver.
    pub is_covering: bool,
    /// Whether employee is in overtime.
    pub is_overtime: bool,
    /// Daily transaction count.
    pub daily_transaction_count: u32,
    /// Weekly hours worked.
    pub weekly_hours: f64,
    /// Days since hire.
    pub days_since_hire: i64,
}

/// Rules for account-specific anomaly patterns.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AccountAnomalyRules {
    /// High-risk account prefixes (e.g., "8" for suspense).
    pub high_risk_prefixes: Vec<String>,
    /// Error multiplier for high-risk accounts.
    pub high_risk_multiplier: f64,
    /// Reconciliation account patterns.
    pub reconciliation_account_patterns: Vec<String>,
    /// Error types for reconciliation accounts.
    pub reconciliation_error_types: Vec<AnomalyType>,
    /// Revenue account patterns.
    pub revenue_account_patterns: Vec<String>,
    /// Fraud types for revenue accounts.
    pub revenue_fraud_types: Vec<AnomalyType>,
    /// Intercompany account patterns.
    pub intercompany_account_patterns: Vec<String>,
    /// Error types for intercompany accounts.
    pub intercompany_error_types: Vec<AnomalyType>,
}

impl Default for AccountAnomalyRules {
    fn default() -> Self {
        Self {
            high_risk_prefixes: vec!["8".to_string(), "9".to_string()],
            high_risk_multiplier: 2.0,
            reconciliation_account_patterns: vec![
                "1290".to_string(), // Clearing accounts
                "2990".to_string(), // Suspense accounts
            ],
            reconciliation_error_types: vec![
                AnomalyType::Error(ErrorType::UnbalancedEntry),
                AnomalyType::Error(ErrorType::MisclassifiedAccount),
            ],
            revenue_account_patterns: vec![
                "4".to_string(), // Revenue accounts typically start with 4
            ],
            revenue_fraud_types: vec![
                AnomalyType::Fraud(FraudType::RevenueManipulation),
                AnomalyType::Fraud(FraudType::PrematureRevenue),
                AnomalyType::Fraud(FraudType::ChannelStuffing),
            ],
            intercompany_account_patterns: vec![
                "1310".to_string(), // IC receivables
                "2310".to_string(), // IC payables
            ],
            intercompany_error_types: vec![
                AnomalyType::Error(ErrorType::WrongCompanyCode),
                AnomalyType::Error(ErrorType::WrongPeriod),
            ],
        }
    }
}

impl AccountAnomalyRules {
    /// Checks if an account is high-risk.
    pub fn is_high_risk(&self, account_code: &str) -> bool {
        self.high_risk_prefixes
            .iter()
            .any(|prefix| account_code.starts_with(prefix))
    }

    /// Checks if an account is a reconciliation account.
    pub fn is_reconciliation_account(&self, account_code: &str) -> bool {
        self.reconciliation_account_patterns
            .iter()
            .any(|pattern| account_code.starts_with(pattern))
    }

    /// Checks if an account is a revenue account.
    pub fn is_revenue_account(&self, account_code: &str) -> bool {
        self.revenue_account_patterns
            .iter()
            .any(|pattern| account_code.starts_with(pattern))
    }

    /// Checks if an account is an intercompany account.
    pub fn is_intercompany_account(&self, account_code: &str) -> bool {
        self.intercompany_account_patterns
            .iter()
            .any(|pattern| account_code.starts_with(pattern))
    }

    /// Gets the error rate multiplier for an account.
    pub fn get_multiplier(&self, context: &AccountContext) -> f64 {
        let mut multiplier = 1.0;

        if context.is_high_risk {
            multiplier *= self.high_risk_multiplier;
        }

        multiplier
    }

    /// Gets applicable anomaly types for an account context.
    pub fn get_applicable_types(&self, context: &AccountContext) -> Vec<AnomalyType> {
        let mut types = Vec::new();

        if context.is_reconciliation {
            types.extend(self.reconciliation_error_types.clone());
        }

        if context.is_revenue {
            types.extend(self.revenue_fraud_types.clone());
        }

        if context.is_intercompany {
            types.extend(self.intercompany_error_types.clone());
        }

        types
    }
}

/// Context information about an account.
#[derive(Debug, Clone, Default)]
pub struct AccountContext {
    /// Account code.
    pub account_code: String,
    /// Whether account is high-risk.
    pub is_high_risk: bool,
    /// Whether account is a reconciliation account.
    pub is_reconciliation: bool,
    /// Whether account is a revenue account.
    pub is_revenue: bool,
    /// Whether account is an intercompany account.
    pub is_intercompany: bool,
}

/// Entity-aware anomaly injector.
pub struct EntityAwareInjector {
    config: EntityAwareConfig,
}

impl Default for EntityAwareInjector {
    fn default() -> Self {
        Self::new(EntityAwareConfig::default())
    }
}

impl EntityAwareInjector {
    /// Creates a new entity-aware injector.
    pub fn new(config: EntityAwareConfig) -> Self {
        Self { config }
    }

    /// Gets the combined rate multiplier for a transaction context.
    pub fn get_rate_multiplier(
        &self,
        vendor_ctx: Option<&VendorContext>,
        employee_ctx: Option<&EmployeeContext>,
        account_ctx: Option<&AccountContext>,
    ) -> f64 {
        if !self.config.enabled {
            return 1.0;
        }

        let mut multiplier = 1.0;

        if let Some(ctx) = vendor_ctx {
            multiplier *= self.config.vendor_rules.get_multiplier(ctx);
        }

        if let Some(ctx) = employee_ctx {
            multiplier *= self.config.employee_rules.get_multiplier(ctx);
        }

        if let Some(ctx) = account_ctx {
            multiplier *= self.config.account_rules.get_multiplier(ctx);
        }

        multiplier
    }

    /// Gets applicable anomaly types for a transaction context.
    pub fn get_applicable_types(
        &self,
        vendor_ctx: Option<&VendorContext>,
        employee_ctx: Option<&EmployeeContext>,
        account_ctx: Option<&AccountContext>,
    ) -> Vec<AnomalyType> {
        if !self.config.enabled {
            return Vec::new();
        }

        let mut types = Vec::new();

        if let Some(ctx) = vendor_ctx {
            types.extend(self.config.vendor_rules.get_applicable_types(ctx));
        }

        if let Some(ctx) = employee_ctx {
            types.extend(self.config.employee_rules.get_applicable_types(ctx));
        }

        if let Some(ctx) = account_ctx {
            types.extend(self.config.account_rules.get_applicable_types(ctx));
        }

        // Remove duplicates
        types.sort_by(|a, b| format!("{a:?}").cmp(&format!("{b:?}")));
        types.dedup();

        types
    }

    /// Determines if an anomaly should be injected based on context.
    pub fn should_inject<R: Rng>(
        &self,
        base_rate: f64,
        vendor_ctx: Option<&VendorContext>,
        employee_ctx: Option<&EmployeeContext>,
        account_ctx: Option<&AccountContext>,
        rng: &mut R,
    ) -> bool {
        let multiplier = self.get_rate_multiplier(vendor_ctx, employee_ctx, account_ctx);
        let adjusted_rate = (base_rate * multiplier).min(1.0);
        rng.random::<f64>() < adjusted_rate
    }

    /// Builds a vendor context from entity data.
    pub fn build_vendor_context(
        &self,
        vendor_id: impl Into<String>,
        creation_date: NaiveDate,
        last_activity: NaiveDate,
        current_date: NaiveDate,
        total_spend: Decimal,
        is_international: bool,
    ) -> VendorContext {
        let is_new = self
            .config
            .vendor_rules
            .is_new_vendor(creation_date, current_date);
        let is_dormant_reactivation = self
            .config
            .vendor_rules
            .is_dormant_vendor(last_activity, current_date);
        let is_strategic = self.config.vendor_rules.is_strategic_vendor(total_spend);

        VendorContext {
            vendor_id: vendor_id.into(),
            is_new,
            is_strategic,
            is_international,
            is_dormant_reactivation,
            total_spend,
            days_since_creation: (current_date - creation_date).num_days(),
            days_since_last_activity: (current_date - last_activity).num_days(),
        }
    }

    /// Builds an employee context from entity data.
    pub fn build_employee_context(
        &self,
        employee_id: impl Into<String>,
        hire_date: NaiveDate,
        current_date: NaiveDate,
        daily_transaction_count: u32,
        weekly_hours: f64,
        is_covering: bool,
    ) -> EmployeeContext {
        let is_new = self
            .config
            .employee_rules
            .is_new_employee(hire_date, current_date);
        let is_volume_fatigued = self
            .config
            .employee_rules
            .is_volume_fatigue(daily_transaction_count);
        let is_overtime = self.config.employee_rules.is_overtime(weekly_hours);

        EmployeeContext {
            employee_id: employee_id.into(),
            is_new,
            is_volume_fatigued,
            is_covering,
            is_overtime,
            daily_transaction_count,
            weekly_hours,
            days_since_hire: (current_date - hire_date).num_days(),
        }
    }

    /// Builds an account context from account code.
    pub fn build_account_context(&self, account_code: impl Into<String>) -> AccountContext {
        let code = account_code.into();
        let is_high_risk = self.config.account_rules.is_high_risk(&code);
        let is_reconciliation = self.config.account_rules.is_reconciliation_account(&code);
        let is_revenue = self.config.account_rules.is_revenue_account(&code);
        let is_intercompany = self.config.account_rules.is_intercompany_account(&code);

        AccountContext {
            account_code: code,
            is_high_risk,
            is_reconciliation,
            is_revenue,
            is_intercompany,
        }
    }

    /// Returns the configuration.
    pub fn config(&self) -> &EntityAwareConfig {
        &self.config
    }
}

#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod tests {
    use super::*;

    #[test]
    fn test_vendor_rules_new_vendor() {
        let rules = VendorAnomalyRules::default();
        let creation = NaiveDate::from_ymd_opt(2024, 1, 1).unwrap();
        let current = NaiveDate::from_ymd_opt(2024, 2, 1).unwrap(); // 31 days

        assert!(rules.is_new_vendor(creation, current));

        let current_later = NaiveDate::from_ymd_opt(2024, 6, 1).unwrap(); // 152 days
        assert!(!rules.is_new_vendor(creation, current_later));
    }

    #[test]
    fn test_vendor_rules_strategic() {
        let rules = VendorAnomalyRules::default();

        assert!(!rules.is_strategic_vendor(dec!(500000)));
        assert!(rules.is_strategic_vendor(dec!(1500000)));
    }

    #[test]
    fn test_employee_rules_new_employee() {
        let rules = EmployeeAnomalyRules::default();
        let hire = NaiveDate::from_ymd_opt(2024, 1, 1).unwrap();
        let current = NaiveDate::from_ymd_opt(2024, 3, 1).unwrap(); // 60 days

        assert!(rules.is_new_employee(hire, current));

        let current_later = NaiveDate::from_ymd_opt(2024, 9, 1).unwrap(); // 244 days
        assert!(!rules.is_new_employee(hire, current_later));
    }

    #[test]
    fn test_employee_rules_fatigue() {
        let rules = EmployeeAnomalyRules::default();

        assert!(!rules.is_volume_fatigue(30));
        assert!(rules.is_volume_fatigue(60));
    }

    #[test]
    fn test_account_rules() {
        let rules = AccountAnomalyRules::default();

        assert!(rules.is_high_risk("8100"));
        assert!(rules.is_high_risk("9000"));
        assert!(!rules.is_high_risk("4100"));

        assert!(rules.is_revenue_account("4100"));
        assert!(!rules.is_revenue_account("5100"));

        assert!(rules.is_intercompany_account("1310"));
        assert!(rules.is_intercompany_account("2310"));
    }

    #[test]
    fn test_entity_aware_injector() {
        let injector = EntityAwareInjector::default();

        let vendor_ctx = VendorContext {
            vendor_id: "V001".to_string(),
            is_new: true,
            is_strategic: false,
            is_international: false,
            is_dormant_reactivation: false,
            total_spend: dec!(50000),
            days_since_creation: 30,
            days_since_last_activity: 5,
        };

        let multiplier = injector.get_rate_multiplier(Some(&vendor_ctx), None, None);
        assert!(multiplier > 1.0); // New vendor should increase rate
    }

    #[test]
    fn test_build_vendor_context() {
        let injector = EntityAwareInjector::default();

        let ctx = injector.build_vendor_context(
            "V001",
            NaiveDate::from_ymd_opt(2024, 1, 1).unwrap(),
            NaiveDate::from_ymd_opt(2024, 5, 1).unwrap(),
            NaiveDate::from_ymd_opt(2024, 6, 1).unwrap(),
            dec!(2000000),
            true,
        );

        assert!(!ctx.is_new); // 152 days > 90 threshold
        assert!(ctx.is_strategic); // 2M > 1M threshold
        assert!(ctx.is_international);
        assert!(!ctx.is_dormant_reactivation); // 31 days < 180 threshold
    }

    #[test]
    fn test_combined_multiplier() {
        let injector = EntityAwareInjector::default();

        let vendor_ctx = VendorContext {
            is_new: true,
            ..Default::default()
        };

        let employee_ctx = EmployeeContext {
            is_volume_fatigued: true,
            ..Default::default()
        };

        let multiplier = injector.get_rate_multiplier(Some(&vendor_ctx), Some(&employee_ctx), None);

        // Should be new_vendor_multiplier * volume_fatigue_multiplier
        // 2.5 * 1.5 = 3.75
        assert!((multiplier - 3.75).abs() < 0.01);
    }
}