Skip to main content

datasynth_config/
schema.rs

1//! Configuration schema for synthetic data generation.
2
3use datasynth_core::distributions::{
4    AmountDistributionConfig, DebitCreditDistributionConfig, EvenOddDistributionConfig,
5    LineItemDistributionConfig, SeasonalityConfig,
6};
7use datasynth_core::models::{CoAComplexity, IndustrySector};
8use serde::{Deserialize, Serialize};
9use std::path::PathBuf;
10
11/// Root configuration for the synthetic data generator.
12#[derive(Debug, Clone, Serialize, Deserialize)]
13pub struct GeneratorConfig {
14    /// Global settings
15    pub global: GlobalConfig,
16    /// Company configuration
17    pub companies: Vec<CompanyConfig>,
18    /// Chart of Accounts configuration
19    pub chart_of_accounts: ChartOfAccountsConfig,
20    /// Transaction generation settings
21    #[serde(default)]
22    pub transactions: TransactionConfig,
23    /// Output configuration
24    pub output: OutputConfig,
25    /// Fraud simulation settings
26    #[serde(default)]
27    pub fraud: FraudConfig,
28    /// Data quality variation settings
29    #[serde(default)]
30    pub data_quality: DataQualitySchemaConfig,
31    /// Internal Controls System settings
32    #[serde(default)]
33    pub internal_controls: InternalControlsConfig,
34    /// Business process mix
35    #[serde(default)]
36    pub business_processes: BusinessProcessConfig,
37    /// User persona distribution
38    #[serde(default)]
39    pub user_personas: UserPersonaConfig,
40    /// Template configuration for realistic data
41    #[serde(default)]
42    pub templates: TemplateConfig,
43    /// Approval workflow configuration
44    #[serde(default)]
45    pub approval: ApprovalConfig,
46    /// Department structure configuration
47    #[serde(default)]
48    pub departments: DepartmentConfig,
49    /// Master data generation settings
50    #[serde(default)]
51    pub master_data: MasterDataConfig,
52    /// Document flow generation settings
53    #[serde(default)]
54    pub document_flows: DocumentFlowConfig,
55    /// Intercompany transaction settings
56    #[serde(default)]
57    pub intercompany: IntercompanyConfig,
58    /// Balance and trial balance settings
59    #[serde(default)]
60    pub balance: BalanceConfig,
61    /// OCPM (Object-Centric Process Mining) settings
62    #[serde(default)]
63    pub ocpm: OcpmConfig,
64    /// Audit engagement and workpaper generation settings
65    #[serde(default)]
66    pub audit: AuditGenerationConfig,
67    /// Banking KYC/AML transaction generation settings
68    #[serde(default)]
69    pub banking: datasynth_banking::BankingConfig,
70    /// Scenario configuration for metadata and tagging (Phase 1.3)
71    #[serde(default)]
72    pub scenario: ScenarioConfig,
73    /// Temporal drift configuration for simulating distribution changes over time (Phase 2.2)
74    #[serde(default)]
75    pub temporal: TemporalDriftConfig,
76    /// Graph export configuration for accounting network export
77    #[serde(default)]
78    pub graph_export: GraphExportConfig,
79    /// Streaming output API configuration
80    #[serde(default)]
81    pub streaming: StreamingSchemaConfig,
82    /// Rate limiting configuration
83    #[serde(default)]
84    pub rate_limit: RateLimitSchemaConfig,
85    /// Temporal attribute generation configuration
86    #[serde(default)]
87    pub temporal_attributes: TemporalAttributeSchemaConfig,
88    /// Relationship generation configuration
89    #[serde(default)]
90    pub relationships: RelationshipSchemaConfig,
91    /// Accounting standards framework configuration (IFRS, US GAAP)
92    #[serde(default)]
93    pub accounting_standards: AccountingStandardsConfig,
94    /// Audit standards framework configuration (ISA, PCAOB)
95    #[serde(default)]
96    pub audit_standards: AuditStandardsConfig,
97    /// Advanced distribution configuration (mixture models, correlations, regime changes)
98    #[serde(default)]
99    pub distributions: AdvancedDistributionConfig,
100    /// Temporal patterns configuration (business days, period-end dynamics, processing lags)
101    #[serde(default)]
102    pub temporal_patterns: TemporalPatternsConfig,
103    /// Vendor network configuration (multi-tier supply chain modeling)
104    #[serde(default)]
105    pub vendor_network: VendorNetworkSchemaConfig,
106    /// Customer segmentation configuration (value segments, lifecycle stages)
107    #[serde(default)]
108    pub customer_segmentation: CustomerSegmentationSchemaConfig,
109    /// Relationship strength calculation configuration
110    #[serde(default)]
111    pub relationship_strength: RelationshipStrengthSchemaConfig,
112    /// Cross-process link configuration (P2P ↔ O2C via inventory)
113    #[serde(default)]
114    pub cross_process_links: CrossProcessLinksSchemaConfig,
115    /// Organizational events configuration (acquisitions, divestitures, etc.)
116    #[serde(default)]
117    pub organizational_events: OrganizationalEventsSchemaConfig,
118    /// Behavioral drift configuration (vendor, customer, employee behavior)
119    #[serde(default)]
120    pub behavioral_drift: BehavioralDriftSchemaConfig,
121    /// Market drift configuration (economic cycles, commodities, price shocks)
122    #[serde(default)]
123    pub market_drift: MarketDriftSchemaConfig,
124    /// Drift labeling configuration for ground truth generation
125    #[serde(default)]
126    pub drift_labeling: DriftLabelingSchemaConfig,
127    /// Enhanced anomaly injection configuration (multi-stage schemes, correlated injection, near-miss)
128    #[serde(default)]
129    pub anomaly_injection: EnhancedAnomalyConfig,
130    /// Industry-specific transaction and anomaly generation configuration
131    #[serde(default)]
132    pub industry_specific: IndustrySpecificConfig,
133    /// Fingerprint privacy configuration for extraction/synthesis
134    #[serde(default)]
135    pub fingerprint_privacy: FingerprintPrivacyConfig,
136    /// Quality gate configuration for pass/fail thresholds
137    #[serde(default)]
138    pub quality_gates: QualityGatesSchemaConfig,
139    /// Compliance configuration (EU AI Act, content marking)
140    #[serde(default)]
141    pub compliance: ComplianceSchemaConfig,
142    /// Webhook notification configuration
143    #[serde(default)]
144    pub webhooks: WebhookSchemaConfig,
145    /// LLM enrichment configuration (AI-augmented vendor names, descriptions, explanations)
146    #[serde(default)]
147    pub llm: LlmSchemaConfig,
148    /// Diffusion model configuration (statistical diffusion-based data enhancement)
149    #[serde(default)]
150    pub diffusion: DiffusionSchemaConfig,
151    /// Causal generation configuration (structural causal models, interventions)
152    #[serde(default)]
153    pub causal: CausalSchemaConfig,
154
155    // ===== Enterprise Process Chain Extensions =====
156    /// Source-to-Pay (S2C/S2P) configuration (sourcing, contracts, catalogs, scorecards)
157    #[serde(default)]
158    pub source_to_pay: SourceToPayConfig,
159    /// Financial reporting configuration (financial statements, KPIs, budgets)
160    #[serde(default)]
161    pub financial_reporting: FinancialReportingConfig,
162    /// HR process configuration (payroll, time & attendance, expenses)
163    #[serde(default)]
164    pub hr: HrConfig,
165    /// Manufacturing configuration (production orders, WIP, routing)
166    #[serde(default)]
167    pub manufacturing: ManufacturingProcessConfig,
168    /// Sales quote configuration (quote-to-order pipeline)
169    #[serde(default)]
170    pub sales_quotes: SalesQuoteConfig,
171    /// Tax accounting configuration (VAT/GST, sales tax, withholding, provisions, payroll tax)
172    #[serde(default)]
173    pub tax: TaxConfig,
174    /// Treasury and cash management configuration
175    #[serde(default)]
176    pub treasury: TreasuryConfig,
177    /// Project accounting configuration
178    #[serde(default)]
179    pub project_accounting: ProjectAccountingConfig,
180    /// ESG / Sustainability reporting configuration
181    #[serde(default)]
182    pub esg: EsgConfig,
183    /// Country pack configuration (external packs directory, per-country overrides)
184    #[serde(default)]
185    pub country_packs: Option<CountryPacksSchemaConfig>,
186}
187
188/// LLM enrichment configuration.
189///
190/// Controls AI-augmented metadata enrichment using LLM providers.
191/// When enabled, vendor names, transaction descriptions, and anomaly explanations
192/// are enriched using the configured provider (mock by default).
193#[derive(Debug, Clone, Serialize, Deserialize)]
194pub struct LlmSchemaConfig {
195    /// Whether LLM enrichment is enabled.
196    #[serde(default)]
197    pub enabled: bool,
198    /// Provider type: "mock", "openai", "anthropic", "custom".
199    #[serde(default = "default_llm_provider")]
200    pub provider: String,
201    /// Model name/ID for the provider.
202    #[serde(default = "default_llm_model_name")]
203    pub model: String,
204    /// Maximum number of vendor names to enrich per run.
205    #[serde(default = "default_llm_batch_size")]
206    pub max_vendor_enrichments: usize,
207}
208
209fn default_llm_provider() -> String {
210    "mock".to_string()
211}
212
213fn default_llm_model_name() -> String {
214    "gpt-4o-mini".to_string()
215}
216
217fn default_llm_batch_size() -> usize {
218    50
219}
220
221impl Default for LlmSchemaConfig {
222    fn default() -> Self {
223        Self {
224            enabled: false,
225            provider: default_llm_provider(),
226            model: default_llm_model_name(),
227            max_vendor_enrichments: default_llm_batch_size(),
228        }
229    }
230}
231
232/// Diffusion model configuration.
233///
234/// Controls statistical diffusion-based data enhancement that generates samples
235/// matching target distribution properties (means, standard deviations, correlations).
236#[derive(Debug, Clone, Serialize, Deserialize)]
237pub struct DiffusionSchemaConfig {
238    /// Whether diffusion enhancement is enabled.
239    #[serde(default)]
240    pub enabled: bool,
241    /// Number of diffusion steps (higher = better quality, slower).
242    #[serde(default = "default_diffusion_steps")]
243    pub n_steps: usize,
244    /// Noise schedule type: "linear", "cosine", "sigmoid".
245    #[serde(default = "default_diffusion_schedule")]
246    pub schedule: String,
247    /// Number of sample rows to generate for demonstration.
248    #[serde(default = "default_diffusion_sample_size")]
249    pub sample_size: usize,
250}
251
252fn default_diffusion_steps() -> usize {
253    100
254}
255
256fn default_diffusion_schedule() -> String {
257    "linear".to_string()
258}
259
260fn default_diffusion_sample_size() -> usize {
261    100
262}
263
264impl Default for DiffusionSchemaConfig {
265    fn default() -> Self {
266        Self {
267            enabled: false,
268            n_steps: default_diffusion_steps(),
269            schedule: default_diffusion_schedule(),
270            sample_size: default_diffusion_sample_size(),
271        }
272    }
273}
274
275/// Causal generation configuration.
276///
277/// Controls structural causal model (SCM) based data generation that respects
278/// causal relationships between variables, supports do-calculus interventions,
279/// and enables counterfactual scenarios.
280#[derive(Debug, Clone, Serialize, Deserialize)]
281pub struct CausalSchemaConfig {
282    /// Whether causal generation is enabled.
283    #[serde(default)]
284    pub enabled: bool,
285    /// Built-in template to use: "fraud_detection", "revenue_cycle", or "custom".
286    #[serde(default = "default_causal_template")]
287    pub template: String,
288    /// Number of causal samples to generate.
289    #[serde(default = "default_causal_sample_size")]
290    pub sample_size: usize,
291    /// Whether to run causal validation on the output.
292    #[serde(default = "default_true")]
293    pub validate: bool,
294}
295
296fn default_causal_template() -> String {
297    "fraud_detection".to_string()
298}
299
300fn default_causal_sample_size() -> usize {
301    500
302}
303
304impl Default for CausalSchemaConfig {
305    fn default() -> Self {
306        Self {
307            enabled: false,
308            template: default_causal_template(),
309            sample_size: default_causal_sample_size(),
310            validate: true,
311        }
312    }
313}
314
315/// Graph export configuration for accounting network and ML training exports.
316///
317/// This section enables exporting generated data as graphs for:
318/// - Network reconstruction algorithms
319/// - Graph neural network training
320/// - Neo4j graph database import
321#[derive(Debug, Clone, Serialize, Deserialize)]
322pub struct GraphExportConfig {
323    /// Enable graph export.
324    #[serde(default)]
325    pub enabled: bool,
326
327    /// Graph types to generate.
328    #[serde(default = "default_graph_types")]
329    pub graph_types: Vec<GraphTypeConfig>,
330
331    /// Export formats to generate.
332    #[serde(default = "default_graph_formats")]
333    pub formats: Vec<GraphExportFormat>,
334
335    /// Train split ratio for ML datasets.
336    #[serde(default = "default_train_ratio")]
337    pub train_ratio: f64,
338
339    /// Validation split ratio for ML datasets.
340    #[serde(default = "default_val_ratio")]
341    pub validation_ratio: f64,
342
343    /// Random seed for train/val/test splits.
344    #[serde(default)]
345    pub split_seed: Option<u64>,
346
347    /// Output subdirectory for graph exports (relative to output directory).
348    #[serde(default = "default_graph_subdir")]
349    pub output_subdirectory: String,
350
351    /// Multi-layer hypergraph export settings for RustGraph integration.
352    #[serde(default)]
353    pub hypergraph: HypergraphExportSettings,
354}
355
356fn default_graph_types() -> Vec<GraphTypeConfig> {
357    vec![GraphTypeConfig::default()]
358}
359
360fn default_graph_formats() -> Vec<GraphExportFormat> {
361    vec![GraphExportFormat::PytorchGeometric]
362}
363
364fn default_train_ratio() -> f64 {
365    0.7
366}
367
368fn default_val_ratio() -> f64 {
369    0.15
370}
371
372fn default_graph_subdir() -> String {
373    "graphs".to_string()
374}
375
376impl Default for GraphExportConfig {
377    fn default() -> Self {
378        Self {
379            enabled: false,
380            graph_types: default_graph_types(),
381            formats: default_graph_formats(),
382            train_ratio: 0.7,
383            validation_ratio: 0.15,
384            split_seed: None,
385            output_subdirectory: "graphs".to_string(),
386            hypergraph: HypergraphExportSettings::default(),
387        }
388    }
389}
390
391/// Settings for the multi-layer hypergraph export (RustGraph integration).
392///
393/// Produces a 3-layer hypergraph:
394/// - Layer 1: Governance & Controls (COSO, SOX, internal controls, organizational)
395/// - Layer 2: Process Events (P2P/O2C document flows, OCPM events)
396/// - Layer 3: Accounting Network (GL accounts, journal entries as hyperedges)
397#[derive(Debug, Clone, Serialize, Deserialize)]
398pub struct HypergraphExportSettings {
399    /// Enable hypergraph export.
400    #[serde(default)]
401    pub enabled: bool,
402
403    /// Maximum total nodes across all layers (default 50000).
404    #[serde(default = "default_hypergraph_max_nodes")]
405    pub max_nodes: usize,
406
407    /// Aggregation strategy when node budget is exceeded.
408    #[serde(default = "default_aggregation_strategy")]
409    pub aggregation_strategy: String,
410
411    /// Layer 1 (Governance & Controls) settings.
412    #[serde(default)]
413    pub governance_layer: GovernanceLayerSettings,
414
415    /// Layer 2 (Process Events) settings.
416    #[serde(default)]
417    pub process_layer: ProcessLayerSettings,
418
419    /// Layer 3 (Accounting Network) settings.
420    #[serde(default)]
421    pub accounting_layer: AccountingLayerSettings,
422
423    /// Cross-layer edge generation settings.
424    #[serde(default)]
425    pub cross_layer: CrossLayerSettings,
426
427    /// Output subdirectory for hypergraph files (relative to graph output directory).
428    #[serde(default = "default_hypergraph_subdir")]
429    pub output_subdirectory: String,
430
431    /// Output format: "native" (default) for internal field names, "unified" for RustGraph format.
432    #[serde(default = "default_hypergraph_format")]
433    pub output_format: String,
434
435    /// Optional URL for streaming unified JSONL to a RustGraph ingest endpoint.
436    #[serde(default)]
437    pub stream_target: Option<String>,
438
439    /// Batch size for streaming (number of JSONL lines per HTTP POST). Default: 1000.
440    #[serde(default = "default_stream_batch_size")]
441    pub stream_batch_size: usize,
442}
443
444fn default_hypergraph_max_nodes() -> usize {
445    50_000
446}
447
448fn default_aggregation_strategy() -> String {
449    "pool_by_counterparty".to_string()
450}
451
452fn default_hypergraph_subdir() -> String {
453    "hypergraph".to_string()
454}
455
456fn default_hypergraph_format() -> String {
457    "native".to_string()
458}
459
460fn default_stream_batch_size() -> usize {
461    1000
462}
463
464impl Default for HypergraphExportSettings {
465    fn default() -> Self {
466        Self {
467            enabled: false,
468            max_nodes: 50_000,
469            aggregation_strategy: "pool_by_counterparty".to_string(),
470            governance_layer: GovernanceLayerSettings::default(),
471            process_layer: ProcessLayerSettings::default(),
472            accounting_layer: AccountingLayerSettings::default(),
473            cross_layer: CrossLayerSettings::default(),
474            output_subdirectory: "hypergraph".to_string(),
475            output_format: "native".to_string(),
476            stream_target: None,
477            stream_batch_size: 1000,
478        }
479    }
480}
481
482/// Layer 1: Governance & Controls layer settings.
483#[derive(Debug, Clone, Serialize, Deserialize)]
484pub struct GovernanceLayerSettings {
485    /// Include COSO framework nodes (5 components + 17 principles).
486    #[serde(default = "default_true")]
487    pub include_coso: bool,
488    /// Include internal control nodes.
489    #[serde(default = "default_true")]
490    pub include_controls: bool,
491    /// Include SOX assertion nodes.
492    #[serde(default = "default_true")]
493    pub include_sox: bool,
494    /// Include vendor master data nodes.
495    #[serde(default = "default_true")]
496    pub include_vendors: bool,
497    /// Include customer master data nodes.
498    #[serde(default = "default_true")]
499    pub include_customers: bool,
500    /// Include employee/organizational nodes.
501    #[serde(default = "default_true")]
502    pub include_employees: bool,
503}
504
505impl Default for GovernanceLayerSettings {
506    fn default() -> Self {
507        Self {
508            include_coso: true,
509            include_controls: true,
510            include_sox: true,
511            include_vendors: true,
512            include_customers: true,
513            include_employees: true,
514        }
515    }
516}
517
518/// Layer 2: Process Events layer settings.
519#[derive(Debug, Clone, Serialize, Deserialize)]
520pub struct ProcessLayerSettings {
521    /// Include P2P (Procure-to-Pay) document flow nodes.
522    #[serde(default = "default_true")]
523    pub include_p2p: bool,
524    /// Include O2C (Order-to-Cash) document flow nodes.
525    #[serde(default = "default_true")]
526    pub include_o2c: bool,
527    /// Include S2C (Source-to-Contract) document flow nodes.
528    #[serde(default = "default_true")]
529    pub include_s2c: bool,
530    /// Include H2R (Hire-to-Retire) document flow nodes.
531    #[serde(default = "default_true")]
532    pub include_h2r: bool,
533    /// Include MFG (Manufacturing) document flow nodes.
534    #[serde(default = "default_true")]
535    pub include_mfg: bool,
536    /// Include BANK (Banking) document flow nodes.
537    #[serde(default = "default_true")]
538    pub include_bank: bool,
539    /// Include AUDIT document flow nodes.
540    #[serde(default = "default_true")]
541    pub include_audit: bool,
542    /// Include R2R (Record-to-Report) document flow nodes (bank recon + period close).
543    #[serde(default = "default_true")]
544    pub include_r2r: bool,
545    /// Export OCPM events as hyperedges.
546    #[serde(default = "default_true")]
547    pub events_as_hyperedges: bool,
548    /// Threshold: if a counterparty has more documents than this, aggregate into pool nodes.
549    #[serde(default = "default_docs_per_counterparty_threshold")]
550    pub docs_per_counterparty_threshold: usize,
551}
552
553fn default_docs_per_counterparty_threshold() -> usize {
554    20
555}
556
557impl Default for ProcessLayerSettings {
558    fn default() -> Self {
559        Self {
560            include_p2p: true,
561            include_o2c: true,
562            include_s2c: true,
563            include_h2r: true,
564            include_mfg: true,
565            include_bank: true,
566            include_audit: true,
567            include_r2r: true,
568            events_as_hyperedges: true,
569            docs_per_counterparty_threshold: 20,
570        }
571    }
572}
573
574/// Layer 3: Accounting Network layer settings.
575#[derive(Debug, Clone, Serialize, Deserialize)]
576pub struct AccountingLayerSettings {
577    /// Include GL account nodes.
578    #[serde(default = "default_true")]
579    pub include_accounts: bool,
580    /// Export journal entries as hyperedges (debit+credit accounts as participants).
581    #[serde(default = "default_true")]
582    pub je_as_hyperedges: bool,
583}
584
585impl Default for AccountingLayerSettings {
586    fn default() -> Self {
587        Self {
588            include_accounts: true,
589            je_as_hyperedges: true,
590        }
591    }
592}
593
594/// Cross-layer edge generation settings.
595#[derive(Debug, Clone, Serialize, Deserialize)]
596pub struct CrossLayerSettings {
597    /// Generate cross-layer edges (Control→Account, Vendor→PO, etc.).
598    #[serde(default = "default_true")]
599    pub enabled: bool,
600}
601
602impl Default for CrossLayerSettings {
603    fn default() -> Self {
604        Self { enabled: true }
605    }
606}
607
608/// Configuration for a specific graph type to export.
609#[derive(Debug, Clone, Serialize, Deserialize)]
610pub struct GraphTypeConfig {
611    /// Name identifier for this graph configuration.
612    #[serde(default = "default_graph_name")]
613    pub name: String,
614
615    /// Whether to aggregate parallel edges between the same nodes.
616    #[serde(default)]
617    pub aggregate_edges: bool,
618
619    /// Minimum edge weight to include (filters out small transactions).
620    #[serde(default)]
621    pub min_edge_weight: f64,
622
623    /// Whether to include document nodes (creates hub-and-spoke structure).
624    #[serde(default)]
625    pub include_document_nodes: bool,
626}
627
628fn default_graph_name() -> String {
629    "accounting_network".to_string()
630}
631
632impl Default for GraphTypeConfig {
633    fn default() -> Self {
634        Self {
635            name: "accounting_network".to_string(),
636            aggregate_edges: false,
637            min_edge_weight: 0.0,
638            include_document_nodes: false,
639        }
640    }
641}
642
643/// Export format for graph data.
644#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
645#[serde(rename_all = "snake_case")]
646pub enum GraphExportFormat {
647    /// PyTorch Geometric format (.npy files + metadata.json).
648    PytorchGeometric,
649    /// Neo4j format (CSV files + Cypher import scripts).
650    Neo4j,
651    /// Deep Graph Library format.
652    Dgl,
653    /// RustGraph/RustAssureTwin JSON format.
654    RustGraph,
655    /// RustGraph multi-layer hypergraph format (nodes.jsonl + edges.jsonl + hyperedges.jsonl).
656    RustGraphHypergraph,
657}
658
659/// Scenario configuration for metadata, tagging, and ML training setup.
660///
661/// This section enables tracking the purpose and characteristics of a generation run.
662#[derive(Debug, Clone, Default, Serialize, Deserialize)]
663pub struct ScenarioConfig {
664    /// Tags for categorizing and filtering datasets.
665    /// Examples: "fraud_detection", "retail", "month_end_stress", "ml_training"
666    #[serde(default)]
667    pub tags: Vec<String>,
668
669    /// Data quality profile preset.
670    /// - "clean": Minimal data quality issues (0.1% missing, 0.05% typos)
671    /// - "noisy": Moderate issues (5% missing, 2% typos, 1% duplicates)
672    /// - "legacy": Heavy issues simulating legacy system data (10% missing, 5% typos)
673    #[serde(default)]
674    pub profile: Option<String>,
675
676    /// Human-readable description of the scenario purpose.
677    #[serde(default)]
678    pub description: Option<String>,
679
680    /// Whether this run is for ML training (enables balanced labeling).
681    #[serde(default)]
682    pub ml_training: bool,
683
684    /// Target anomaly class balance for ML training.
685    /// If set, anomalies will be injected to achieve this ratio.
686    #[serde(default)]
687    pub target_anomaly_ratio: Option<f64>,
688
689    /// Custom metadata key-value pairs.
690    #[serde(default)]
691    pub metadata: std::collections::HashMap<String, String>,
692}
693
694/// Temporal drift configuration for simulating distribution changes over time.
695///
696/// This enables generation of data that shows realistic temporal evolution,
697/// useful for training drift detection models and testing temporal robustness.
698#[derive(Debug, Clone, Serialize, Deserialize)]
699pub struct TemporalDriftConfig {
700    /// Enable temporal drift simulation.
701    #[serde(default)]
702    pub enabled: bool,
703
704    /// Amount mean drift per period (e.g., 0.02 = 2% mean shift per month).
705    /// Simulates gradual inflation or business growth.
706    #[serde(default = "default_amount_drift")]
707    pub amount_mean_drift: f64,
708
709    /// Amount variance drift per period (e.g., 0.01 = 1% variance increase per month).
710    /// Simulates increasing volatility over time.
711    #[serde(default)]
712    pub amount_variance_drift: f64,
713
714    /// Anomaly rate drift per period (e.g., 0.001 = 0.1% increase per month).
715    /// Simulates increasing fraud attempts or degrading controls.
716    #[serde(default)]
717    pub anomaly_rate_drift: f64,
718
719    /// Concept drift rate - how quickly feature distributions change (0.0-1.0).
720    /// Higher values cause more rapid distribution shifts.
721    #[serde(default = "default_concept_drift")]
722    pub concept_drift_rate: f64,
723
724    /// Sudden drift events - probability of a sudden distribution shift in any period.
725    #[serde(default)]
726    pub sudden_drift_probability: f64,
727
728    /// Magnitude of sudden drift events when they occur (multiplier).
729    #[serde(default = "default_sudden_drift_magnitude")]
730    pub sudden_drift_magnitude: f64,
731
732    /// Seasonal drift - enable cyclic patterns that repeat annually.
733    #[serde(default)]
734    pub seasonal_drift: bool,
735
736    /// Drift start period (0 = from beginning). Use to simulate stable baseline before drift.
737    #[serde(default)]
738    pub drift_start_period: u32,
739
740    /// Drift type: "gradual", "sudden", "recurring", "mixed"
741    #[serde(default = "default_drift_type")]
742    pub drift_type: DriftType,
743}
744
745fn default_amount_drift() -> f64 {
746    0.02
747}
748
749fn default_concept_drift() -> f64 {
750    0.01
751}
752
753fn default_sudden_drift_magnitude() -> f64 {
754    2.0
755}
756
757fn default_drift_type() -> DriftType {
758    DriftType::Gradual
759}
760
761impl Default for TemporalDriftConfig {
762    fn default() -> Self {
763        Self {
764            enabled: false,
765            amount_mean_drift: 0.02,
766            amount_variance_drift: 0.0,
767            anomaly_rate_drift: 0.0,
768            concept_drift_rate: 0.01,
769            sudden_drift_probability: 0.0,
770            sudden_drift_magnitude: 2.0,
771            seasonal_drift: false,
772            drift_start_period: 0,
773            drift_type: DriftType::Gradual,
774        }
775    }
776}
777
778impl TemporalDriftConfig {
779    /// Convert to core DriftConfig for use in generators.
780    pub fn to_core_config(&self) -> datasynth_core::distributions::DriftConfig {
781        datasynth_core::distributions::DriftConfig {
782            enabled: self.enabled,
783            amount_mean_drift: self.amount_mean_drift,
784            amount_variance_drift: self.amount_variance_drift,
785            anomaly_rate_drift: self.anomaly_rate_drift,
786            concept_drift_rate: self.concept_drift_rate,
787            sudden_drift_probability: self.sudden_drift_probability,
788            sudden_drift_magnitude: self.sudden_drift_magnitude,
789            seasonal_drift: self.seasonal_drift,
790            drift_start_period: self.drift_start_period,
791            drift_type: match self.drift_type {
792                DriftType::Gradual => datasynth_core::distributions::DriftType::Gradual,
793                DriftType::Sudden => datasynth_core::distributions::DriftType::Sudden,
794                DriftType::Recurring => datasynth_core::distributions::DriftType::Recurring,
795                DriftType::Mixed => datasynth_core::distributions::DriftType::Mixed,
796            },
797            regime_changes: Vec::new(),
798            economic_cycle: Default::default(),
799            parameter_drifts: Vec::new(),
800        }
801    }
802}
803
804/// Types of temporal drift patterns.
805#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
806#[serde(rename_all = "snake_case")]
807pub enum DriftType {
808    /// Gradual, continuous drift over time (like inflation).
809    #[default]
810    Gradual,
811    /// Sudden, point-in-time shifts (like policy changes).
812    Sudden,
813    /// Recurring patterns that cycle (like seasonal variations).
814    Recurring,
815    /// Combination of gradual background drift with occasional sudden shifts.
816    Mixed,
817}
818
819// ============================================================================
820// Streaming Output API Configuration (Phase 2)
821// ============================================================================
822
823/// Configuration for streaming output API.
824#[derive(Debug, Clone, Serialize, Deserialize)]
825pub struct StreamingSchemaConfig {
826    /// Enable streaming output.
827    #[serde(default)]
828    pub enabled: bool,
829    /// Buffer size for streaming (number of items).
830    #[serde(default = "default_buffer_size")]
831    pub buffer_size: usize,
832    /// Enable progress reporting.
833    #[serde(default = "default_true")]
834    pub enable_progress: bool,
835    /// Progress reporting interval (number of items).
836    #[serde(default = "default_progress_interval")]
837    pub progress_interval: u64,
838    /// Backpressure strategy.
839    #[serde(default)]
840    pub backpressure: BackpressureSchemaStrategy,
841}
842
843fn default_buffer_size() -> usize {
844    1000
845}
846
847fn default_progress_interval() -> u64 {
848    100
849}
850
851impl Default for StreamingSchemaConfig {
852    fn default() -> Self {
853        Self {
854            enabled: false,
855            buffer_size: 1000,
856            enable_progress: true,
857            progress_interval: 100,
858            backpressure: BackpressureSchemaStrategy::Block,
859        }
860    }
861}
862
863/// Backpressure strategy for streaming output.
864#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
865#[serde(rename_all = "snake_case")]
866pub enum BackpressureSchemaStrategy {
867    /// Block until space is available in the buffer.
868    #[default]
869    Block,
870    /// Drop oldest items when buffer is full.
871    DropOldest,
872    /// Drop newest items when buffer is full.
873    DropNewest,
874    /// Buffer overflow items up to a limit, then block.
875    Buffer,
876}
877
878// ============================================================================
879// Rate Limiting Configuration (Phase 5)
880// ============================================================================
881
882/// Configuration for rate limiting.
883#[derive(Debug, Clone, Serialize, Deserialize)]
884pub struct RateLimitSchemaConfig {
885    /// Enable rate limiting.
886    #[serde(default)]
887    pub enabled: bool,
888    /// Entities per second limit.
889    #[serde(default = "default_entities_per_second")]
890    pub entities_per_second: f64,
891    /// Burst size (number of tokens in bucket).
892    #[serde(default = "default_burst_size")]
893    pub burst_size: u32,
894    /// Backpressure strategy for rate limiting.
895    #[serde(default)]
896    pub backpressure: RateLimitBackpressureSchema,
897}
898
899fn default_entities_per_second() -> f64 {
900    1000.0
901}
902
903fn default_burst_size() -> u32 {
904    100
905}
906
907impl Default for RateLimitSchemaConfig {
908    fn default() -> Self {
909        Self {
910            enabled: false,
911            entities_per_second: 1000.0,
912            burst_size: 100,
913            backpressure: RateLimitBackpressureSchema::Block,
914        }
915    }
916}
917
918/// Backpressure strategy for rate limiting.
919#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
920#[serde(rename_all = "snake_case")]
921pub enum RateLimitBackpressureSchema {
922    /// Block until rate allows.
923    #[default]
924    Block,
925    /// Drop items that exceed rate.
926    Drop,
927    /// Buffer items and process when rate allows.
928    Buffer,
929}
930
931// ============================================================================
932// Temporal Attribute Generation Configuration (Phase 3)
933// ============================================================================
934
935/// Configuration for temporal attribute generation.
936#[derive(Debug, Clone, Serialize, Deserialize)]
937pub struct TemporalAttributeSchemaConfig {
938    /// Enable temporal attribute generation.
939    #[serde(default)]
940    pub enabled: bool,
941    /// Valid time configuration.
942    #[serde(default)]
943    pub valid_time: ValidTimeSchemaConfig,
944    /// Transaction time configuration.
945    #[serde(default)]
946    pub transaction_time: TransactionTimeSchemaConfig,
947    /// Generate version chains for entities.
948    #[serde(default)]
949    pub generate_version_chains: bool,
950    /// Average number of versions per entity.
951    #[serde(default = "default_avg_versions")]
952    pub avg_versions_per_entity: f64,
953}
954
955fn default_avg_versions() -> f64 {
956    1.5
957}
958
959impl Default for TemporalAttributeSchemaConfig {
960    fn default() -> Self {
961        Self {
962            enabled: false,
963            valid_time: ValidTimeSchemaConfig::default(),
964            transaction_time: TransactionTimeSchemaConfig::default(),
965            generate_version_chains: false,
966            avg_versions_per_entity: 1.5,
967        }
968    }
969}
970
971/// Configuration for valid time (business time) generation.
972#[derive(Debug, Clone, Serialize, Deserialize)]
973pub struct ValidTimeSchemaConfig {
974    /// Probability that valid_to is set (entity has ended validity).
975    #[serde(default = "default_closed_probability")]
976    pub closed_probability: f64,
977    /// Average validity duration in days.
978    #[serde(default = "default_avg_validity_days")]
979    pub avg_validity_days: u32,
980    /// Standard deviation of validity duration in days.
981    #[serde(default = "default_validity_stddev")]
982    pub validity_stddev_days: u32,
983}
984
985fn default_closed_probability() -> f64 {
986    0.1
987}
988
989fn default_avg_validity_days() -> u32 {
990    365
991}
992
993fn default_validity_stddev() -> u32 {
994    90
995}
996
997impl Default for ValidTimeSchemaConfig {
998    fn default() -> Self {
999        Self {
1000            closed_probability: 0.1,
1001            avg_validity_days: 365,
1002            validity_stddev_days: 90,
1003        }
1004    }
1005}
1006
1007/// Configuration for transaction time (system time) generation.
1008#[derive(Debug, Clone, Serialize, Deserialize)]
1009pub struct TransactionTimeSchemaConfig {
1010    /// Average recording delay in seconds (0 = immediate).
1011    #[serde(default)]
1012    pub avg_recording_delay_seconds: u32,
1013    /// Allow backdating (recording time before valid time).
1014    #[serde(default)]
1015    pub allow_backdating: bool,
1016    /// Probability of backdating if allowed.
1017    #[serde(default = "default_backdating_probability")]
1018    pub backdating_probability: f64,
1019    /// Maximum backdate days.
1020    #[serde(default = "default_max_backdate_days")]
1021    pub max_backdate_days: u32,
1022}
1023
1024fn default_backdating_probability() -> f64 {
1025    0.01
1026}
1027
1028fn default_max_backdate_days() -> u32 {
1029    30
1030}
1031
1032impl Default for TransactionTimeSchemaConfig {
1033    fn default() -> Self {
1034        Self {
1035            avg_recording_delay_seconds: 0,
1036            allow_backdating: false,
1037            backdating_probability: 0.01,
1038            max_backdate_days: 30,
1039        }
1040    }
1041}
1042
1043// ============================================================================
1044// Relationship Generation Configuration (Phase 4)
1045// ============================================================================
1046
1047/// Configuration for relationship generation.
1048#[derive(Debug, Clone, Serialize, Deserialize)]
1049pub struct RelationshipSchemaConfig {
1050    /// Relationship type definitions.
1051    #[serde(default)]
1052    pub relationship_types: Vec<RelationshipTypeSchemaConfig>,
1053    /// Allow orphan entities (entities with no relationships).
1054    #[serde(default = "default_true")]
1055    pub allow_orphans: bool,
1056    /// Probability of creating an orphan entity.
1057    #[serde(default = "default_orphan_probability")]
1058    pub orphan_probability: f64,
1059    /// Allow circular relationships.
1060    #[serde(default)]
1061    pub allow_circular: bool,
1062    /// Maximum depth for circular relationship detection.
1063    #[serde(default = "default_max_circular_depth")]
1064    pub max_circular_depth: u32,
1065}
1066
1067fn default_orphan_probability() -> f64 {
1068    0.01
1069}
1070
1071fn default_max_circular_depth() -> u32 {
1072    3
1073}
1074
1075impl Default for RelationshipSchemaConfig {
1076    fn default() -> Self {
1077        Self {
1078            relationship_types: Vec::new(),
1079            allow_orphans: true,
1080            orphan_probability: 0.01,
1081            allow_circular: false,
1082            max_circular_depth: 3,
1083        }
1084    }
1085}
1086
1087/// Configuration for a specific relationship type.
1088#[derive(Debug, Clone, Serialize, Deserialize)]
1089pub struct RelationshipTypeSchemaConfig {
1090    /// Name of the relationship type (e.g., "debits", "credits", "created").
1091    pub name: String,
1092    /// Source entity type (e.g., "journal_entry").
1093    pub source_type: String,
1094    /// Target entity type (e.g., "account").
1095    pub target_type: String,
1096    /// Cardinality rule for this relationship.
1097    #[serde(default)]
1098    pub cardinality: CardinalitySchemaRule,
1099    /// Weight for this relationship in random selection.
1100    #[serde(default = "default_relationship_weight")]
1101    pub weight: f64,
1102    /// Whether this relationship is required.
1103    #[serde(default)]
1104    pub required: bool,
1105    /// Whether this relationship is directed.
1106    #[serde(default = "default_true")]
1107    pub directed: bool,
1108}
1109
1110fn default_relationship_weight() -> f64 {
1111    1.0
1112}
1113
1114impl Default for RelationshipTypeSchemaConfig {
1115    fn default() -> Self {
1116        Self {
1117            name: String::new(),
1118            source_type: String::new(),
1119            target_type: String::new(),
1120            cardinality: CardinalitySchemaRule::default(),
1121            weight: 1.0,
1122            required: false,
1123            directed: true,
1124        }
1125    }
1126}
1127
1128/// Cardinality rule for relationships in schema config.
1129#[derive(Debug, Clone, Serialize, Deserialize)]
1130#[serde(rename_all = "snake_case")]
1131pub enum CardinalitySchemaRule {
1132    /// One source to one target.
1133    OneToOne,
1134    /// One source to many targets.
1135    OneToMany {
1136        /// Minimum number of targets.
1137        min: u32,
1138        /// Maximum number of targets.
1139        max: u32,
1140    },
1141    /// Many sources to one target.
1142    ManyToOne {
1143        /// Minimum number of sources.
1144        min: u32,
1145        /// Maximum number of sources.
1146        max: u32,
1147    },
1148    /// Many sources to many targets.
1149    ManyToMany {
1150        /// Minimum targets per source.
1151        min_per_source: u32,
1152        /// Maximum targets per source.
1153        max_per_source: u32,
1154    },
1155}
1156
1157impl Default for CardinalitySchemaRule {
1158    fn default() -> Self {
1159        Self::OneToMany { min: 1, max: 5 }
1160    }
1161}
1162
1163/// Global configuration settings.
1164#[derive(Debug, Clone, Serialize, Deserialize)]
1165pub struct GlobalConfig {
1166    /// Random seed for reproducibility
1167    pub seed: Option<u64>,
1168    /// Industry sector
1169    pub industry: IndustrySector,
1170    /// Simulation start date (YYYY-MM-DD)
1171    pub start_date: String,
1172    /// Simulation period in months
1173    pub period_months: u32,
1174    /// Base currency for group reporting
1175    #[serde(default = "default_currency")]
1176    pub group_currency: String,
1177    /// Enable parallel generation
1178    #[serde(default = "default_true")]
1179    pub parallel: bool,
1180    /// Number of worker threads (0 = auto-detect)
1181    #[serde(default)]
1182    pub worker_threads: usize,
1183    /// Memory limit in MB (0 = unlimited)
1184    #[serde(default)]
1185    pub memory_limit_mb: usize,
1186}
1187
1188fn default_currency() -> String {
1189    "USD".to_string()
1190}
1191fn default_true() -> bool {
1192    true
1193}
1194
1195/// Company code configuration.
1196#[derive(Debug, Clone, Serialize, Deserialize)]
1197pub struct CompanyConfig {
1198    /// Company code identifier
1199    pub code: String,
1200    /// Company name
1201    pub name: String,
1202    /// Local currency (ISO 4217)
1203    pub currency: String,
1204    /// Country code (ISO 3166-1 alpha-2)
1205    pub country: String,
1206    /// Fiscal year variant
1207    #[serde(default = "default_fiscal_variant")]
1208    pub fiscal_year_variant: String,
1209    /// Transaction volume per year
1210    pub annual_transaction_volume: TransactionVolume,
1211    /// Company-specific transaction weight
1212    #[serde(default = "default_weight")]
1213    pub volume_weight: f64,
1214}
1215
1216fn default_fiscal_variant() -> String {
1217    "K4".to_string()
1218}
1219fn default_weight() -> f64 {
1220    1.0
1221}
1222
1223/// Transaction volume presets.
1224#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
1225#[serde(rename_all = "snake_case")]
1226pub enum TransactionVolume {
1227    /// 10,000 transactions per year
1228    TenK,
1229    /// 100,000 transactions per year
1230    HundredK,
1231    /// 1,000,000 transactions per year
1232    OneM,
1233    /// 10,000,000 transactions per year
1234    TenM,
1235    /// 100,000,000 transactions per year
1236    HundredM,
1237    /// Custom count
1238    Custom(u64),
1239}
1240
1241impl TransactionVolume {
1242    /// Get the transaction count.
1243    pub fn count(&self) -> u64 {
1244        match self {
1245            Self::TenK => 10_000,
1246            Self::HundredK => 100_000,
1247            Self::OneM => 1_000_000,
1248            Self::TenM => 10_000_000,
1249            Self::HundredM => 100_000_000,
1250            Self::Custom(n) => *n,
1251        }
1252    }
1253}
1254
1255/// Chart of Accounts configuration.
1256#[derive(Debug, Clone, Serialize, Deserialize)]
1257pub struct ChartOfAccountsConfig {
1258    /// CoA complexity level
1259    pub complexity: CoAComplexity,
1260    /// Use industry-specific accounts
1261    #[serde(default = "default_true")]
1262    pub industry_specific: bool,
1263    /// Custom account definitions file
1264    pub custom_accounts: Option<PathBuf>,
1265    /// Minimum hierarchy depth
1266    #[serde(default = "default_min_depth")]
1267    pub min_hierarchy_depth: u8,
1268    /// Maximum hierarchy depth
1269    #[serde(default = "default_max_depth")]
1270    pub max_hierarchy_depth: u8,
1271}
1272
1273fn default_min_depth() -> u8 {
1274    2
1275}
1276fn default_max_depth() -> u8 {
1277    5
1278}
1279
1280impl Default for ChartOfAccountsConfig {
1281    fn default() -> Self {
1282        Self {
1283            complexity: CoAComplexity::Small,
1284            industry_specific: true,
1285            custom_accounts: None,
1286            min_hierarchy_depth: default_min_depth(),
1287            max_hierarchy_depth: default_max_depth(),
1288        }
1289    }
1290}
1291
1292/// Transaction generation configuration.
1293#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1294pub struct TransactionConfig {
1295    /// Line item distribution
1296    #[serde(default)]
1297    pub line_item_distribution: LineItemDistributionConfig,
1298    /// Debit/credit balance distribution
1299    #[serde(default)]
1300    pub debit_credit_distribution: DebitCreditDistributionConfig,
1301    /// Even/odd line count distribution
1302    #[serde(default)]
1303    pub even_odd_distribution: EvenOddDistributionConfig,
1304    /// Transaction source distribution
1305    #[serde(default)]
1306    pub source_distribution: SourceDistribution,
1307    /// Seasonality configuration
1308    #[serde(default)]
1309    pub seasonality: SeasonalityConfig,
1310    /// Amount distribution
1311    #[serde(default)]
1312    pub amounts: AmountDistributionConfig,
1313    /// Benford's Law compliance configuration
1314    #[serde(default)]
1315    pub benford: BenfordConfig,
1316}
1317
1318/// Benford's Law compliance configuration.
1319#[derive(Debug, Clone, Serialize, Deserialize)]
1320pub struct BenfordConfig {
1321    /// Enable Benford's Law compliance for amount generation
1322    #[serde(default = "default_true")]
1323    pub enabled: bool,
1324    /// Tolerance for deviation from ideal Benford distribution (0.0-1.0)
1325    #[serde(default = "default_benford_tolerance")]
1326    pub tolerance: f64,
1327    /// Transaction sources exempt from Benford's Law (fixed amounts)
1328    #[serde(default)]
1329    pub exempt_sources: Vec<BenfordExemption>,
1330}
1331
1332fn default_benford_tolerance() -> f64 {
1333    0.05
1334}
1335
1336impl Default for BenfordConfig {
1337    fn default() -> Self {
1338        Self {
1339            enabled: true,
1340            tolerance: default_benford_tolerance(),
1341            exempt_sources: vec![BenfordExemption::Recurring, BenfordExemption::Payroll],
1342        }
1343    }
1344}
1345
1346/// Types of transactions exempt from Benford's Law.
1347#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
1348#[serde(rename_all = "snake_case")]
1349pub enum BenfordExemption {
1350    /// Recurring fixed amounts (rent, subscriptions)
1351    Recurring,
1352    /// Payroll (standardized salaries)
1353    Payroll,
1354    /// Fixed fees and charges
1355    FixedFees,
1356    /// Round number purchases (often legitimate)
1357    RoundAmounts,
1358}
1359
1360/// Distribution of transaction sources.
1361#[derive(Debug, Clone, Serialize, Deserialize)]
1362pub struct SourceDistribution {
1363    /// Manual entries percentage
1364    pub manual: f64,
1365    /// Automated system entries
1366    pub automated: f64,
1367    /// Recurring entries
1368    pub recurring: f64,
1369    /// Adjustment entries
1370    pub adjustment: f64,
1371}
1372
1373impl Default for SourceDistribution {
1374    fn default() -> Self {
1375        Self {
1376            manual: 0.20,
1377            automated: 0.70,
1378            recurring: 0.07,
1379            adjustment: 0.03,
1380        }
1381    }
1382}
1383
1384/// Output configuration.
1385#[derive(Debug, Clone, Serialize, Deserialize)]
1386pub struct OutputConfig {
1387    /// Output mode
1388    #[serde(default)]
1389    pub mode: OutputMode,
1390    /// Output directory
1391    pub output_directory: PathBuf,
1392    /// File formats to generate
1393    #[serde(default = "default_formats")]
1394    pub formats: Vec<FileFormat>,
1395    /// Compression settings
1396    #[serde(default)]
1397    pub compression: CompressionConfig,
1398    /// Batch size for writes
1399    #[serde(default = "default_batch_size")]
1400    pub batch_size: usize,
1401    /// Include ACDOCA format
1402    #[serde(default = "default_true")]
1403    pub include_acdoca: bool,
1404    /// Include BSEG format
1405    #[serde(default)]
1406    pub include_bseg: bool,
1407    /// Partition by fiscal period
1408    #[serde(default = "default_true")]
1409    pub partition_by_period: bool,
1410    /// Partition by company code
1411    #[serde(default)]
1412    pub partition_by_company: bool,
1413}
1414
1415fn default_formats() -> Vec<FileFormat> {
1416    vec![FileFormat::Parquet]
1417}
1418fn default_batch_size() -> usize {
1419    100_000
1420}
1421
1422impl Default for OutputConfig {
1423    fn default() -> Self {
1424        Self {
1425            mode: OutputMode::FlatFile,
1426            output_directory: PathBuf::from("./output"),
1427            formats: default_formats(),
1428            compression: CompressionConfig::default(),
1429            batch_size: default_batch_size(),
1430            include_acdoca: true,
1431            include_bseg: false,
1432            partition_by_period: true,
1433            partition_by_company: false,
1434        }
1435    }
1436}
1437
1438/// Output mode.
1439#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize)]
1440#[serde(rename_all = "snake_case")]
1441pub enum OutputMode {
1442    /// Stream records as generated
1443    Streaming,
1444    /// Write to flat files
1445    #[default]
1446    FlatFile,
1447    /// Both streaming and flat file
1448    Both,
1449}
1450
1451/// Supported file formats.
1452#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
1453#[serde(rename_all = "snake_case")]
1454pub enum FileFormat {
1455    Csv,
1456    Parquet,
1457    Json,
1458    JsonLines,
1459}
1460
1461/// Compression configuration.
1462#[derive(Debug, Clone, Serialize, Deserialize)]
1463pub struct CompressionConfig {
1464    /// Enable compression
1465    #[serde(default = "default_true")]
1466    pub enabled: bool,
1467    /// Compression algorithm
1468    #[serde(default)]
1469    pub algorithm: CompressionAlgorithm,
1470    /// Compression level (1-9)
1471    #[serde(default = "default_compression_level")]
1472    pub level: u8,
1473}
1474
1475fn default_compression_level() -> u8 {
1476    3
1477}
1478
1479impl Default for CompressionConfig {
1480    fn default() -> Self {
1481        Self {
1482            enabled: true,
1483            algorithm: CompressionAlgorithm::default(),
1484            level: default_compression_level(),
1485        }
1486    }
1487}
1488
1489/// Compression algorithms.
1490#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize)]
1491#[serde(rename_all = "snake_case")]
1492pub enum CompressionAlgorithm {
1493    Gzip,
1494    #[default]
1495    Zstd,
1496    Lz4,
1497    Snappy,
1498}
1499
1500/// Fraud simulation configuration.
1501#[derive(Debug, Clone, Serialize, Deserialize)]
1502pub struct FraudConfig {
1503    /// Enable fraud scenario generation
1504    #[serde(default)]
1505    pub enabled: bool,
1506    /// Overall fraud rate (0.0 to 1.0)
1507    #[serde(default = "default_fraud_rate")]
1508    pub fraud_rate: f64,
1509    /// Fraud type distribution
1510    #[serde(default)]
1511    pub fraud_type_distribution: FraudTypeDistribution,
1512    /// Enable fraud clustering
1513    #[serde(default)]
1514    pub clustering_enabled: bool,
1515    /// Clustering factor
1516    #[serde(default = "default_clustering_factor")]
1517    pub clustering_factor: f64,
1518    /// Approval thresholds for threshold-adjacent fraud pattern
1519    #[serde(default = "default_approval_thresholds")]
1520    pub approval_thresholds: Vec<f64>,
1521}
1522
1523fn default_approval_thresholds() -> Vec<f64> {
1524    vec![1000.0, 5000.0, 10000.0, 25000.0, 50000.0, 100000.0]
1525}
1526
1527fn default_fraud_rate() -> f64 {
1528    0.005
1529}
1530fn default_clustering_factor() -> f64 {
1531    3.0
1532}
1533
1534impl Default for FraudConfig {
1535    fn default() -> Self {
1536        Self {
1537            enabled: false,
1538            fraud_rate: default_fraud_rate(),
1539            fraud_type_distribution: FraudTypeDistribution::default(),
1540            clustering_enabled: false,
1541            clustering_factor: default_clustering_factor(),
1542            approval_thresholds: default_approval_thresholds(),
1543        }
1544    }
1545}
1546
1547/// Distribution of fraud types.
1548#[derive(Debug, Clone, Serialize, Deserialize)]
1549pub struct FraudTypeDistribution {
1550    pub suspense_account_abuse: f64,
1551    pub fictitious_transaction: f64,
1552    pub revenue_manipulation: f64,
1553    pub expense_capitalization: f64,
1554    pub split_transaction: f64,
1555    pub timing_anomaly: f64,
1556    pub unauthorized_access: f64,
1557    pub duplicate_payment: f64,
1558}
1559
1560impl Default for FraudTypeDistribution {
1561    fn default() -> Self {
1562        Self {
1563            suspense_account_abuse: 0.25,
1564            fictitious_transaction: 0.15,
1565            revenue_manipulation: 0.10,
1566            expense_capitalization: 0.10,
1567            split_transaction: 0.15,
1568            timing_anomaly: 0.10,
1569            unauthorized_access: 0.10,
1570            duplicate_payment: 0.05,
1571        }
1572    }
1573}
1574
1575/// Internal Controls System (ICS) configuration.
1576#[derive(Debug, Clone, Serialize, Deserialize)]
1577pub struct InternalControlsConfig {
1578    /// Enable internal controls system
1579    #[serde(default)]
1580    pub enabled: bool,
1581    /// Rate at which controls result in exceptions (0.0 - 1.0)
1582    #[serde(default = "default_exception_rate")]
1583    pub exception_rate: f64,
1584    /// Rate at which SoD violations occur (0.0 - 1.0)
1585    #[serde(default = "default_sod_violation_rate")]
1586    pub sod_violation_rate: f64,
1587    /// Export control master data to separate files
1588    #[serde(default = "default_true")]
1589    pub export_control_master_data: bool,
1590    /// SOX materiality threshold for marking transactions as SOX-relevant
1591    #[serde(default = "default_sox_materiality_threshold")]
1592    pub sox_materiality_threshold: f64,
1593    /// Enable COSO 2013 framework integration
1594    #[serde(default = "default_true")]
1595    pub coso_enabled: bool,
1596    /// Include entity-level controls in generation
1597    #[serde(default)]
1598    pub include_entity_level_controls: bool,
1599    /// Target maturity level for controls
1600    /// Valid values: "ad_hoc", "repeatable", "defined", "managed", "optimized", "mixed"
1601    #[serde(default = "default_target_maturity_level")]
1602    pub target_maturity_level: String,
1603}
1604
1605fn default_exception_rate() -> f64 {
1606    0.02
1607}
1608
1609fn default_sod_violation_rate() -> f64 {
1610    0.01
1611}
1612
1613fn default_sox_materiality_threshold() -> f64 {
1614    10000.0
1615}
1616
1617fn default_target_maturity_level() -> String {
1618    "mixed".to_string()
1619}
1620
1621impl Default for InternalControlsConfig {
1622    fn default() -> Self {
1623        Self {
1624            enabled: false,
1625            exception_rate: default_exception_rate(),
1626            sod_violation_rate: default_sod_violation_rate(),
1627            export_control_master_data: true,
1628            sox_materiality_threshold: default_sox_materiality_threshold(),
1629            coso_enabled: true,
1630            include_entity_level_controls: false,
1631            target_maturity_level: default_target_maturity_level(),
1632        }
1633    }
1634}
1635
1636/// Business process configuration.
1637#[derive(Debug, Clone, Serialize, Deserialize)]
1638pub struct BusinessProcessConfig {
1639    /// Order-to-Cash weight
1640    #[serde(default = "default_o2c")]
1641    pub o2c_weight: f64,
1642    /// Procure-to-Pay weight
1643    #[serde(default = "default_p2p")]
1644    pub p2p_weight: f64,
1645    /// Record-to-Report weight
1646    #[serde(default = "default_r2r")]
1647    pub r2r_weight: f64,
1648    /// Hire-to-Retire weight
1649    #[serde(default = "default_h2r")]
1650    pub h2r_weight: f64,
1651    /// Acquire-to-Retire weight
1652    #[serde(default = "default_a2r")]
1653    pub a2r_weight: f64,
1654}
1655
1656fn default_o2c() -> f64 {
1657    0.35
1658}
1659fn default_p2p() -> f64 {
1660    0.30
1661}
1662fn default_r2r() -> f64 {
1663    0.20
1664}
1665fn default_h2r() -> f64 {
1666    0.10
1667}
1668fn default_a2r() -> f64 {
1669    0.05
1670}
1671
1672impl Default for BusinessProcessConfig {
1673    fn default() -> Self {
1674        Self {
1675            o2c_weight: default_o2c(),
1676            p2p_weight: default_p2p(),
1677            r2r_weight: default_r2r(),
1678            h2r_weight: default_h2r(),
1679            a2r_weight: default_a2r(),
1680        }
1681    }
1682}
1683
1684/// User persona configuration.
1685#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1686pub struct UserPersonaConfig {
1687    /// Distribution of user personas
1688    #[serde(default)]
1689    pub persona_distribution: PersonaDistribution,
1690    /// Users per persona type
1691    #[serde(default)]
1692    pub users_per_persona: UsersPerPersona,
1693}
1694
1695/// Distribution of user personas for transaction generation.
1696#[derive(Debug, Clone, Serialize, Deserialize)]
1697pub struct PersonaDistribution {
1698    pub junior_accountant: f64,
1699    pub senior_accountant: f64,
1700    pub controller: f64,
1701    pub manager: f64,
1702    pub automated_system: f64,
1703}
1704
1705impl Default for PersonaDistribution {
1706    fn default() -> Self {
1707        Self {
1708            junior_accountant: 0.15,
1709            senior_accountant: 0.15,
1710            controller: 0.05,
1711            manager: 0.05,
1712            automated_system: 0.60,
1713        }
1714    }
1715}
1716
1717/// Number of users per persona type.
1718#[derive(Debug, Clone, Serialize, Deserialize)]
1719pub struct UsersPerPersona {
1720    pub junior_accountant: usize,
1721    pub senior_accountant: usize,
1722    pub controller: usize,
1723    pub manager: usize,
1724    pub automated_system: usize,
1725}
1726
1727impl Default for UsersPerPersona {
1728    fn default() -> Self {
1729        Self {
1730            junior_accountant: 10,
1731            senior_accountant: 5,
1732            controller: 2,
1733            manager: 3,
1734            automated_system: 20,
1735        }
1736    }
1737}
1738
1739/// Template configuration for realistic data generation.
1740#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1741pub struct TemplateConfig {
1742    /// Name generation settings
1743    #[serde(default)]
1744    pub names: NameTemplateConfig,
1745    /// Description generation settings
1746    #[serde(default)]
1747    pub descriptions: DescriptionTemplateConfig,
1748    /// Reference number settings
1749    #[serde(default)]
1750    pub references: ReferenceTemplateConfig,
1751}
1752
1753/// Name template configuration.
1754#[derive(Debug, Clone, Serialize, Deserialize)]
1755pub struct NameTemplateConfig {
1756    /// Distribution of name cultures
1757    #[serde(default)]
1758    pub culture_distribution: CultureDistribution,
1759    /// Email domain for generated users
1760    #[serde(default = "default_email_domain")]
1761    pub email_domain: String,
1762    /// Generate realistic display names
1763    #[serde(default = "default_true")]
1764    pub generate_realistic_names: bool,
1765}
1766
1767fn default_email_domain() -> String {
1768    "company.com".to_string()
1769}
1770
1771impl Default for NameTemplateConfig {
1772    fn default() -> Self {
1773        Self {
1774            culture_distribution: CultureDistribution::default(),
1775            email_domain: default_email_domain(),
1776            generate_realistic_names: true,
1777        }
1778    }
1779}
1780
1781/// Distribution of name cultures for generation.
1782#[derive(Debug, Clone, Serialize, Deserialize)]
1783pub struct CultureDistribution {
1784    pub western_us: f64,
1785    pub hispanic: f64,
1786    pub german: f64,
1787    pub french: f64,
1788    pub chinese: f64,
1789    pub japanese: f64,
1790    pub indian: f64,
1791}
1792
1793impl Default for CultureDistribution {
1794    fn default() -> Self {
1795        Self {
1796            western_us: 0.40,
1797            hispanic: 0.20,
1798            german: 0.10,
1799            french: 0.05,
1800            chinese: 0.10,
1801            japanese: 0.05,
1802            indian: 0.10,
1803        }
1804    }
1805}
1806
1807/// Description template configuration.
1808#[derive(Debug, Clone, Serialize, Deserialize)]
1809pub struct DescriptionTemplateConfig {
1810    /// Generate header text for journal entries
1811    #[serde(default = "default_true")]
1812    pub generate_header_text: bool,
1813    /// Generate line text for journal entry lines
1814    #[serde(default = "default_true")]
1815    pub generate_line_text: bool,
1816}
1817
1818impl Default for DescriptionTemplateConfig {
1819    fn default() -> Self {
1820        Self {
1821            generate_header_text: true,
1822            generate_line_text: true,
1823        }
1824    }
1825}
1826
1827/// Reference number template configuration.
1828#[derive(Debug, Clone, Serialize, Deserialize)]
1829pub struct ReferenceTemplateConfig {
1830    /// Generate reference numbers
1831    #[serde(default = "default_true")]
1832    pub generate_references: bool,
1833    /// Invoice prefix
1834    #[serde(default = "default_invoice_prefix")]
1835    pub invoice_prefix: String,
1836    /// Purchase order prefix
1837    #[serde(default = "default_po_prefix")]
1838    pub po_prefix: String,
1839    /// Sales order prefix
1840    #[serde(default = "default_so_prefix")]
1841    pub so_prefix: String,
1842}
1843
1844fn default_invoice_prefix() -> String {
1845    "INV".to_string()
1846}
1847fn default_po_prefix() -> String {
1848    "PO".to_string()
1849}
1850fn default_so_prefix() -> String {
1851    "SO".to_string()
1852}
1853
1854impl Default for ReferenceTemplateConfig {
1855    fn default() -> Self {
1856        Self {
1857            generate_references: true,
1858            invoice_prefix: default_invoice_prefix(),
1859            po_prefix: default_po_prefix(),
1860            so_prefix: default_so_prefix(),
1861        }
1862    }
1863}
1864
1865/// Approval workflow configuration.
1866#[derive(Debug, Clone, Serialize, Deserialize)]
1867pub struct ApprovalConfig {
1868    /// Enable approval workflow generation
1869    #[serde(default)]
1870    pub enabled: bool,
1871    /// Threshold below which transactions are auto-approved
1872    #[serde(default = "default_auto_approve_threshold")]
1873    pub auto_approve_threshold: f64,
1874    /// Rate at which approvals are rejected (0.0 to 1.0)
1875    #[serde(default = "default_rejection_rate")]
1876    pub rejection_rate: f64,
1877    /// Rate at which approvals require revision (0.0 to 1.0)
1878    #[serde(default = "default_revision_rate")]
1879    pub revision_rate: f64,
1880    /// Average delay in hours for approval processing
1881    #[serde(default = "default_approval_delay_hours")]
1882    pub average_approval_delay_hours: f64,
1883    /// Approval chain thresholds
1884    #[serde(default)]
1885    pub thresholds: Vec<ApprovalThresholdConfig>,
1886}
1887
1888fn default_auto_approve_threshold() -> f64 {
1889    1000.0
1890}
1891fn default_rejection_rate() -> f64 {
1892    0.02
1893}
1894fn default_revision_rate() -> f64 {
1895    0.05
1896}
1897fn default_approval_delay_hours() -> f64 {
1898    4.0
1899}
1900
1901impl Default for ApprovalConfig {
1902    fn default() -> Self {
1903        Self {
1904            enabled: false,
1905            auto_approve_threshold: default_auto_approve_threshold(),
1906            rejection_rate: default_rejection_rate(),
1907            revision_rate: default_revision_rate(),
1908            average_approval_delay_hours: default_approval_delay_hours(),
1909            thresholds: vec![
1910                ApprovalThresholdConfig {
1911                    amount: 1000.0,
1912                    level: 1,
1913                    roles: vec!["senior_accountant".to_string()],
1914                },
1915                ApprovalThresholdConfig {
1916                    amount: 10000.0,
1917                    level: 2,
1918                    roles: vec!["senior_accountant".to_string(), "controller".to_string()],
1919                },
1920                ApprovalThresholdConfig {
1921                    amount: 100000.0,
1922                    level: 3,
1923                    roles: vec![
1924                        "senior_accountant".to_string(),
1925                        "controller".to_string(),
1926                        "manager".to_string(),
1927                    ],
1928                },
1929                ApprovalThresholdConfig {
1930                    amount: 500000.0,
1931                    level: 4,
1932                    roles: vec![
1933                        "senior_accountant".to_string(),
1934                        "controller".to_string(),
1935                        "manager".to_string(),
1936                        "executive".to_string(),
1937                    ],
1938                },
1939            ],
1940        }
1941    }
1942}
1943
1944/// Configuration for a single approval threshold.
1945#[derive(Debug, Clone, Serialize, Deserialize)]
1946pub struct ApprovalThresholdConfig {
1947    /// Amount threshold
1948    pub amount: f64,
1949    /// Approval level required
1950    pub level: u8,
1951    /// Roles that can approve at this level
1952    pub roles: Vec<String>,
1953}
1954
1955/// Department configuration.
1956#[derive(Debug, Clone, Serialize, Deserialize)]
1957pub struct DepartmentConfig {
1958    /// Enable department assignment
1959    #[serde(default)]
1960    pub enabled: bool,
1961    /// Multiplier for department headcounts
1962    #[serde(default = "default_headcount_multiplier")]
1963    pub headcount_multiplier: f64,
1964    /// Custom department definitions (optional)
1965    #[serde(default)]
1966    pub custom_departments: Vec<CustomDepartmentConfig>,
1967}
1968
1969fn default_headcount_multiplier() -> f64 {
1970    1.0
1971}
1972
1973impl Default for DepartmentConfig {
1974    fn default() -> Self {
1975        Self {
1976            enabled: false,
1977            headcount_multiplier: default_headcount_multiplier(),
1978            custom_departments: Vec::new(),
1979        }
1980    }
1981}
1982
1983/// Custom department definition.
1984#[derive(Debug, Clone, Serialize, Deserialize)]
1985pub struct CustomDepartmentConfig {
1986    /// Department code
1987    pub code: String,
1988    /// Department name
1989    pub name: String,
1990    /// Associated cost center
1991    #[serde(default)]
1992    pub cost_center: Option<String>,
1993    /// Primary business processes
1994    #[serde(default)]
1995    pub primary_processes: Vec<String>,
1996    /// Parent department code
1997    #[serde(default)]
1998    pub parent_code: Option<String>,
1999}
2000
2001// ============================================================================
2002// Master Data Configuration
2003// ============================================================================
2004
2005/// Master data generation configuration.
2006#[derive(Debug, Clone, Default, Serialize, Deserialize)]
2007pub struct MasterDataConfig {
2008    /// Vendor master data settings
2009    #[serde(default)]
2010    pub vendors: VendorMasterConfig,
2011    /// Customer master data settings
2012    #[serde(default)]
2013    pub customers: CustomerMasterConfig,
2014    /// Material master data settings
2015    #[serde(default)]
2016    pub materials: MaterialMasterConfig,
2017    /// Fixed asset master data settings
2018    #[serde(default)]
2019    pub fixed_assets: FixedAssetMasterConfig,
2020    /// Employee master data settings
2021    #[serde(default)]
2022    pub employees: EmployeeMasterConfig,
2023    /// Cost center master data settings
2024    #[serde(default)]
2025    pub cost_centers: CostCenterMasterConfig,
2026}
2027
2028/// Vendor master data configuration.
2029#[derive(Debug, Clone, Serialize, Deserialize)]
2030pub struct VendorMasterConfig {
2031    /// Number of vendors to generate
2032    #[serde(default = "default_vendor_count")]
2033    pub count: usize,
2034    /// Percentage of vendors that are intercompany (0.0 to 1.0)
2035    #[serde(default = "default_intercompany_percent")]
2036    pub intercompany_percent: f64,
2037    /// Payment terms distribution
2038    #[serde(default)]
2039    pub payment_terms_distribution: PaymentTermsDistribution,
2040    /// Vendor behavior distribution
2041    #[serde(default)]
2042    pub behavior_distribution: VendorBehaviorDistribution,
2043    /// Generate bank account details
2044    #[serde(default = "default_true")]
2045    pub generate_bank_accounts: bool,
2046    /// Generate tax IDs
2047    #[serde(default = "default_true")]
2048    pub generate_tax_ids: bool,
2049}
2050
2051fn default_vendor_count() -> usize {
2052    500
2053}
2054
2055fn default_intercompany_percent() -> f64 {
2056    0.05
2057}
2058
2059impl Default for VendorMasterConfig {
2060    fn default() -> Self {
2061        Self {
2062            count: default_vendor_count(),
2063            intercompany_percent: default_intercompany_percent(),
2064            payment_terms_distribution: PaymentTermsDistribution::default(),
2065            behavior_distribution: VendorBehaviorDistribution::default(),
2066            generate_bank_accounts: true,
2067            generate_tax_ids: true,
2068        }
2069    }
2070}
2071
2072/// Payment terms distribution for vendors.
2073#[derive(Debug, Clone, Serialize, Deserialize)]
2074pub struct PaymentTermsDistribution {
2075    /// Net 30 days
2076    pub net_30: f64,
2077    /// Net 60 days
2078    pub net_60: f64,
2079    /// Net 90 days
2080    pub net_90: f64,
2081    /// 2% 10 Net 30 (early payment discount)
2082    pub two_ten_net_30: f64,
2083    /// Due on receipt
2084    pub due_on_receipt: f64,
2085    /// End of month
2086    pub end_of_month: f64,
2087}
2088
2089impl Default for PaymentTermsDistribution {
2090    fn default() -> Self {
2091        Self {
2092            net_30: 0.40,
2093            net_60: 0.20,
2094            net_90: 0.10,
2095            two_ten_net_30: 0.15,
2096            due_on_receipt: 0.05,
2097            end_of_month: 0.10,
2098        }
2099    }
2100}
2101
2102/// Vendor behavior distribution.
2103#[derive(Debug, Clone, Serialize, Deserialize)]
2104pub struct VendorBehaviorDistribution {
2105    /// Reliable vendors (consistent delivery, quality)
2106    pub reliable: f64,
2107    /// Sometimes late vendors
2108    pub sometimes_late: f64,
2109    /// Inconsistent quality vendors
2110    pub inconsistent_quality: f64,
2111    /// Premium vendors (high quality, premium pricing)
2112    pub premium: f64,
2113    /// Budget vendors (lower quality, lower pricing)
2114    pub budget: f64,
2115}
2116
2117impl Default for VendorBehaviorDistribution {
2118    fn default() -> Self {
2119        Self {
2120            reliable: 0.50,
2121            sometimes_late: 0.20,
2122            inconsistent_quality: 0.10,
2123            premium: 0.10,
2124            budget: 0.10,
2125        }
2126    }
2127}
2128
2129/// Customer master data configuration.
2130#[derive(Debug, Clone, Serialize, Deserialize)]
2131pub struct CustomerMasterConfig {
2132    /// Number of customers to generate
2133    #[serde(default = "default_customer_count")]
2134    pub count: usize,
2135    /// Percentage of customers that are intercompany (0.0 to 1.0)
2136    #[serde(default = "default_intercompany_percent")]
2137    pub intercompany_percent: f64,
2138    /// Credit rating distribution
2139    #[serde(default)]
2140    pub credit_rating_distribution: CreditRatingDistribution,
2141    /// Payment behavior distribution
2142    #[serde(default)]
2143    pub payment_behavior_distribution: PaymentBehaviorDistribution,
2144    /// Generate credit limits based on rating
2145    #[serde(default = "default_true")]
2146    pub generate_credit_limits: bool,
2147}
2148
2149fn default_customer_count() -> usize {
2150    2000
2151}
2152
2153impl Default for CustomerMasterConfig {
2154    fn default() -> Self {
2155        Self {
2156            count: default_customer_count(),
2157            intercompany_percent: default_intercompany_percent(),
2158            credit_rating_distribution: CreditRatingDistribution::default(),
2159            payment_behavior_distribution: PaymentBehaviorDistribution::default(),
2160            generate_credit_limits: true,
2161        }
2162    }
2163}
2164
2165/// Credit rating distribution for customers.
2166#[derive(Debug, Clone, Serialize, Deserialize)]
2167pub struct CreditRatingDistribution {
2168    /// AAA rating
2169    pub aaa: f64,
2170    /// AA rating
2171    pub aa: f64,
2172    /// A rating
2173    pub a: f64,
2174    /// BBB rating
2175    pub bbb: f64,
2176    /// BB rating
2177    pub bb: f64,
2178    /// B rating
2179    pub b: f64,
2180    /// Below B rating
2181    pub below_b: f64,
2182}
2183
2184impl Default for CreditRatingDistribution {
2185    fn default() -> Self {
2186        Self {
2187            aaa: 0.05,
2188            aa: 0.10,
2189            a: 0.20,
2190            bbb: 0.30,
2191            bb: 0.20,
2192            b: 0.10,
2193            below_b: 0.05,
2194        }
2195    }
2196}
2197
2198/// Payment behavior distribution for customers.
2199#[derive(Debug, Clone, Serialize, Deserialize)]
2200pub struct PaymentBehaviorDistribution {
2201    /// Always pays early
2202    pub early_payer: f64,
2203    /// Pays on time
2204    pub on_time: f64,
2205    /// Occasionally late
2206    pub occasional_late: f64,
2207    /// Frequently late
2208    pub frequent_late: f64,
2209    /// Takes early payment discounts
2210    pub discount_taker: f64,
2211}
2212
2213impl Default for PaymentBehaviorDistribution {
2214    fn default() -> Self {
2215        Self {
2216            early_payer: 0.10,
2217            on_time: 0.50,
2218            occasional_late: 0.25,
2219            frequent_late: 0.10,
2220            discount_taker: 0.05,
2221        }
2222    }
2223}
2224
2225/// Material master data configuration.
2226#[derive(Debug, Clone, Serialize, Deserialize)]
2227pub struct MaterialMasterConfig {
2228    /// Number of materials to generate
2229    #[serde(default = "default_material_count")]
2230    pub count: usize,
2231    /// Material type distribution
2232    #[serde(default)]
2233    pub type_distribution: MaterialTypeDistribution,
2234    /// Valuation method distribution
2235    #[serde(default)]
2236    pub valuation_distribution: ValuationMethodDistribution,
2237    /// Percentage of materials with BOM (bill of materials)
2238    #[serde(default = "default_bom_percent")]
2239    pub bom_percent: f64,
2240    /// Maximum BOM depth
2241    #[serde(default = "default_max_bom_depth")]
2242    pub max_bom_depth: u8,
2243}
2244
2245fn default_material_count() -> usize {
2246    5000
2247}
2248
2249fn default_bom_percent() -> f64 {
2250    0.20
2251}
2252
2253fn default_max_bom_depth() -> u8 {
2254    3
2255}
2256
2257impl Default for MaterialMasterConfig {
2258    fn default() -> Self {
2259        Self {
2260            count: default_material_count(),
2261            type_distribution: MaterialTypeDistribution::default(),
2262            valuation_distribution: ValuationMethodDistribution::default(),
2263            bom_percent: default_bom_percent(),
2264            max_bom_depth: default_max_bom_depth(),
2265        }
2266    }
2267}
2268
2269/// Material type distribution.
2270#[derive(Debug, Clone, Serialize, Deserialize)]
2271pub struct MaterialTypeDistribution {
2272    /// Raw materials
2273    pub raw_material: f64,
2274    /// Semi-finished goods
2275    pub semi_finished: f64,
2276    /// Finished goods
2277    pub finished_good: f64,
2278    /// Trading goods (purchased for resale)
2279    pub trading_good: f64,
2280    /// Operating supplies
2281    pub operating_supply: f64,
2282    /// Services
2283    pub service: f64,
2284}
2285
2286impl Default for MaterialTypeDistribution {
2287    fn default() -> Self {
2288        Self {
2289            raw_material: 0.30,
2290            semi_finished: 0.15,
2291            finished_good: 0.25,
2292            trading_good: 0.15,
2293            operating_supply: 0.10,
2294            service: 0.05,
2295        }
2296    }
2297}
2298
2299/// Valuation method distribution for materials.
2300#[derive(Debug, Clone, Serialize, Deserialize)]
2301pub struct ValuationMethodDistribution {
2302    /// Standard cost
2303    pub standard_cost: f64,
2304    /// Moving average
2305    pub moving_average: f64,
2306    /// FIFO (First In, First Out)
2307    pub fifo: f64,
2308    /// LIFO (Last In, First Out)
2309    pub lifo: f64,
2310}
2311
2312impl Default for ValuationMethodDistribution {
2313    fn default() -> Self {
2314        Self {
2315            standard_cost: 0.50,
2316            moving_average: 0.30,
2317            fifo: 0.15,
2318            lifo: 0.05,
2319        }
2320    }
2321}
2322
2323/// Fixed asset master data configuration.
2324#[derive(Debug, Clone, Serialize, Deserialize)]
2325pub struct FixedAssetMasterConfig {
2326    /// Number of fixed assets to generate
2327    #[serde(default = "default_asset_count")]
2328    pub count: usize,
2329    /// Asset class distribution
2330    #[serde(default)]
2331    pub class_distribution: AssetClassDistribution,
2332    /// Depreciation method distribution
2333    #[serde(default)]
2334    pub depreciation_distribution: DepreciationMethodDistribution,
2335    /// Percentage of assets that are fully depreciated
2336    #[serde(default = "default_fully_depreciated_percent")]
2337    pub fully_depreciated_percent: f64,
2338    /// Generate acquisition history
2339    #[serde(default = "default_true")]
2340    pub generate_acquisition_history: bool,
2341}
2342
2343fn default_asset_count() -> usize {
2344    800
2345}
2346
2347fn default_fully_depreciated_percent() -> f64 {
2348    0.15
2349}
2350
2351impl Default for FixedAssetMasterConfig {
2352    fn default() -> Self {
2353        Self {
2354            count: default_asset_count(),
2355            class_distribution: AssetClassDistribution::default(),
2356            depreciation_distribution: DepreciationMethodDistribution::default(),
2357            fully_depreciated_percent: default_fully_depreciated_percent(),
2358            generate_acquisition_history: true,
2359        }
2360    }
2361}
2362
2363/// Asset class distribution.
2364#[derive(Debug, Clone, Serialize, Deserialize)]
2365pub struct AssetClassDistribution {
2366    /// Buildings and structures
2367    pub buildings: f64,
2368    /// Machinery and equipment
2369    pub machinery: f64,
2370    /// Vehicles
2371    pub vehicles: f64,
2372    /// IT equipment
2373    pub it_equipment: f64,
2374    /// Furniture and fixtures
2375    pub furniture: f64,
2376    /// Land (non-depreciable)
2377    pub land: f64,
2378    /// Leasehold improvements
2379    pub leasehold: f64,
2380}
2381
2382impl Default for AssetClassDistribution {
2383    fn default() -> Self {
2384        Self {
2385            buildings: 0.15,
2386            machinery: 0.30,
2387            vehicles: 0.15,
2388            it_equipment: 0.20,
2389            furniture: 0.10,
2390            land: 0.05,
2391            leasehold: 0.05,
2392        }
2393    }
2394}
2395
2396/// Depreciation method distribution.
2397#[derive(Debug, Clone, Serialize, Deserialize)]
2398pub struct DepreciationMethodDistribution {
2399    /// Straight line
2400    pub straight_line: f64,
2401    /// Declining balance
2402    pub declining_balance: f64,
2403    /// Double declining balance
2404    pub double_declining: f64,
2405    /// Sum of years' digits
2406    pub sum_of_years: f64,
2407    /// Units of production
2408    pub units_of_production: f64,
2409}
2410
2411impl Default for DepreciationMethodDistribution {
2412    fn default() -> Self {
2413        Self {
2414            straight_line: 0.60,
2415            declining_balance: 0.20,
2416            double_declining: 0.10,
2417            sum_of_years: 0.05,
2418            units_of_production: 0.05,
2419        }
2420    }
2421}
2422
2423/// Employee master data configuration.
2424#[derive(Debug, Clone, Serialize, Deserialize)]
2425pub struct EmployeeMasterConfig {
2426    /// Number of employees to generate
2427    #[serde(default = "default_employee_count")]
2428    pub count: usize,
2429    /// Generate organizational hierarchy
2430    #[serde(default = "default_true")]
2431    pub generate_hierarchy: bool,
2432    /// Maximum hierarchy depth
2433    #[serde(default = "default_hierarchy_depth")]
2434    pub max_hierarchy_depth: u8,
2435    /// Average span of control (direct reports per manager)
2436    #[serde(default = "default_span_of_control")]
2437    pub average_span_of_control: f64,
2438    /// Approval limit distribution by job level
2439    #[serde(default)]
2440    pub approval_limits: ApprovalLimitDistribution,
2441    /// Department distribution
2442    #[serde(default)]
2443    pub department_distribution: EmployeeDepartmentDistribution,
2444}
2445
2446fn default_employee_count() -> usize {
2447    1500
2448}
2449
2450fn default_hierarchy_depth() -> u8 {
2451    6
2452}
2453
2454fn default_span_of_control() -> f64 {
2455    5.0
2456}
2457
2458impl Default for EmployeeMasterConfig {
2459    fn default() -> Self {
2460        Self {
2461            count: default_employee_count(),
2462            generate_hierarchy: true,
2463            max_hierarchy_depth: default_hierarchy_depth(),
2464            average_span_of_control: default_span_of_control(),
2465            approval_limits: ApprovalLimitDistribution::default(),
2466            department_distribution: EmployeeDepartmentDistribution::default(),
2467        }
2468    }
2469}
2470
2471/// Approval limit distribution by job level.
2472#[derive(Debug, Clone, Serialize, Deserialize)]
2473pub struct ApprovalLimitDistribution {
2474    /// Staff level approval limit
2475    #[serde(default = "default_staff_limit")]
2476    pub staff: f64,
2477    /// Senior staff approval limit
2478    #[serde(default = "default_senior_limit")]
2479    pub senior: f64,
2480    /// Manager approval limit
2481    #[serde(default = "default_manager_limit")]
2482    pub manager: f64,
2483    /// Director approval limit
2484    #[serde(default = "default_director_limit")]
2485    pub director: f64,
2486    /// VP approval limit
2487    #[serde(default = "default_vp_limit")]
2488    pub vp: f64,
2489    /// Executive approval limit
2490    #[serde(default = "default_executive_limit")]
2491    pub executive: f64,
2492}
2493
2494fn default_staff_limit() -> f64 {
2495    1000.0
2496}
2497fn default_senior_limit() -> f64 {
2498    5000.0
2499}
2500fn default_manager_limit() -> f64 {
2501    25000.0
2502}
2503fn default_director_limit() -> f64 {
2504    100000.0
2505}
2506fn default_vp_limit() -> f64 {
2507    500000.0
2508}
2509fn default_executive_limit() -> f64 {
2510    f64::INFINITY
2511}
2512
2513impl Default for ApprovalLimitDistribution {
2514    fn default() -> Self {
2515        Self {
2516            staff: default_staff_limit(),
2517            senior: default_senior_limit(),
2518            manager: default_manager_limit(),
2519            director: default_director_limit(),
2520            vp: default_vp_limit(),
2521            executive: default_executive_limit(),
2522        }
2523    }
2524}
2525
2526/// Employee distribution across departments.
2527#[derive(Debug, Clone, Serialize, Deserialize)]
2528pub struct EmployeeDepartmentDistribution {
2529    /// Finance and Accounting
2530    pub finance: f64,
2531    /// Procurement
2532    pub procurement: f64,
2533    /// Sales
2534    pub sales: f64,
2535    /// Warehouse and Logistics
2536    pub warehouse: f64,
2537    /// IT
2538    pub it: f64,
2539    /// Human Resources
2540    pub hr: f64,
2541    /// Operations
2542    pub operations: f64,
2543    /// Executive
2544    pub executive: f64,
2545}
2546
2547impl Default for EmployeeDepartmentDistribution {
2548    fn default() -> Self {
2549        Self {
2550            finance: 0.12,
2551            procurement: 0.10,
2552            sales: 0.25,
2553            warehouse: 0.15,
2554            it: 0.10,
2555            hr: 0.05,
2556            operations: 0.20,
2557            executive: 0.03,
2558        }
2559    }
2560}
2561
2562/// Cost center master data configuration.
2563#[derive(Debug, Clone, Serialize, Deserialize)]
2564pub struct CostCenterMasterConfig {
2565    /// Number of cost centers to generate
2566    #[serde(default = "default_cost_center_count")]
2567    pub count: usize,
2568    /// Generate cost center hierarchy
2569    #[serde(default = "default_true")]
2570    pub generate_hierarchy: bool,
2571    /// Maximum hierarchy depth
2572    #[serde(default = "default_cc_hierarchy_depth")]
2573    pub max_hierarchy_depth: u8,
2574}
2575
2576fn default_cost_center_count() -> usize {
2577    50
2578}
2579
2580fn default_cc_hierarchy_depth() -> u8 {
2581    3
2582}
2583
2584impl Default for CostCenterMasterConfig {
2585    fn default() -> Self {
2586        Self {
2587            count: default_cost_center_count(),
2588            generate_hierarchy: true,
2589            max_hierarchy_depth: default_cc_hierarchy_depth(),
2590        }
2591    }
2592}
2593
2594// ============================================================================
2595// Document Flow Configuration
2596// ============================================================================
2597
2598/// Document flow generation configuration.
2599#[derive(Debug, Clone, Serialize, Deserialize)]
2600pub struct DocumentFlowConfig {
2601    /// P2P (Procure-to-Pay) flow configuration
2602    #[serde(default)]
2603    pub p2p: P2PFlowConfig,
2604    /// O2C (Order-to-Cash) flow configuration
2605    #[serde(default)]
2606    pub o2c: O2CFlowConfig,
2607    /// Generate document reference chains
2608    #[serde(default = "default_true")]
2609    pub generate_document_references: bool,
2610    /// Export document flow graph
2611    #[serde(default)]
2612    pub export_flow_graph: bool,
2613}
2614
2615impl Default for DocumentFlowConfig {
2616    fn default() -> Self {
2617        Self {
2618            p2p: P2PFlowConfig::default(),
2619            o2c: O2CFlowConfig::default(),
2620            generate_document_references: true,
2621            export_flow_graph: false,
2622        }
2623    }
2624}
2625
2626/// P2P (Procure-to-Pay) flow configuration.
2627#[derive(Debug, Clone, Serialize, Deserialize)]
2628pub struct P2PFlowConfig {
2629    /// Enable P2P document flow generation
2630    #[serde(default = "default_true")]
2631    pub enabled: bool,
2632    /// Three-way match success rate (PO-GR-Invoice)
2633    #[serde(default = "default_three_way_match_rate")]
2634    pub three_way_match_rate: f64,
2635    /// Rate of partial deliveries
2636    #[serde(default = "default_partial_delivery_rate")]
2637    pub partial_delivery_rate: f64,
2638    /// Rate of price variances between PO and Invoice
2639    #[serde(default = "default_price_variance_rate")]
2640    pub price_variance_rate: f64,
2641    /// Maximum price variance percentage
2642    #[serde(default = "default_max_price_variance")]
2643    pub max_price_variance_percent: f64,
2644    /// Rate of quantity variances between PO/GR and Invoice
2645    #[serde(default = "default_quantity_variance_rate")]
2646    pub quantity_variance_rate: f64,
2647    /// Average days from PO to goods receipt
2648    #[serde(default = "default_po_to_gr_days")]
2649    pub average_po_to_gr_days: u32,
2650    /// Average days from GR to invoice
2651    #[serde(default = "default_gr_to_invoice_days")]
2652    pub average_gr_to_invoice_days: u32,
2653    /// Average days from invoice to payment
2654    #[serde(default = "default_invoice_to_payment_days")]
2655    pub average_invoice_to_payment_days: u32,
2656    /// PO line count distribution
2657    #[serde(default)]
2658    pub line_count_distribution: DocumentLineCountDistribution,
2659    /// Payment behavior configuration
2660    #[serde(default)]
2661    pub payment_behavior: P2PPaymentBehaviorConfig,
2662}
2663
2664fn default_three_way_match_rate() -> f64 {
2665    0.95
2666}
2667
2668fn default_partial_delivery_rate() -> f64 {
2669    0.15
2670}
2671
2672fn default_price_variance_rate() -> f64 {
2673    0.08
2674}
2675
2676fn default_max_price_variance() -> f64 {
2677    0.05
2678}
2679
2680fn default_quantity_variance_rate() -> f64 {
2681    0.05
2682}
2683
2684fn default_po_to_gr_days() -> u32 {
2685    14
2686}
2687
2688fn default_gr_to_invoice_days() -> u32 {
2689    5
2690}
2691
2692fn default_invoice_to_payment_days() -> u32 {
2693    30
2694}
2695
2696impl Default for P2PFlowConfig {
2697    fn default() -> Self {
2698        Self {
2699            enabled: true,
2700            three_way_match_rate: default_three_way_match_rate(),
2701            partial_delivery_rate: default_partial_delivery_rate(),
2702            price_variance_rate: default_price_variance_rate(),
2703            max_price_variance_percent: default_max_price_variance(),
2704            quantity_variance_rate: default_quantity_variance_rate(),
2705            average_po_to_gr_days: default_po_to_gr_days(),
2706            average_gr_to_invoice_days: default_gr_to_invoice_days(),
2707            average_invoice_to_payment_days: default_invoice_to_payment_days(),
2708            line_count_distribution: DocumentLineCountDistribution::default(),
2709            payment_behavior: P2PPaymentBehaviorConfig::default(),
2710        }
2711    }
2712}
2713
2714// ============================================================================
2715// P2P Payment Behavior Configuration
2716// ============================================================================
2717
2718/// P2P payment behavior configuration.
2719#[derive(Debug, Clone, Serialize, Deserialize)]
2720pub struct P2PPaymentBehaviorConfig {
2721    /// Rate of late payments (beyond due date)
2722    #[serde(default = "default_p2p_late_payment_rate")]
2723    pub late_payment_rate: f64,
2724    /// Distribution of late payment days
2725    #[serde(default)]
2726    pub late_payment_days_distribution: LatePaymentDaysDistribution,
2727    /// Rate of partial payments
2728    #[serde(default = "default_p2p_partial_payment_rate")]
2729    pub partial_payment_rate: f64,
2730    /// Rate of payment corrections (NSF, chargebacks, reversals)
2731    #[serde(default = "default_p2p_payment_correction_rate")]
2732    pub payment_correction_rate: f64,
2733}
2734
2735fn default_p2p_late_payment_rate() -> f64 {
2736    0.15
2737}
2738
2739fn default_p2p_partial_payment_rate() -> f64 {
2740    0.05
2741}
2742
2743fn default_p2p_payment_correction_rate() -> f64 {
2744    0.02
2745}
2746
2747impl Default for P2PPaymentBehaviorConfig {
2748    fn default() -> Self {
2749        Self {
2750            late_payment_rate: default_p2p_late_payment_rate(),
2751            late_payment_days_distribution: LatePaymentDaysDistribution::default(),
2752            partial_payment_rate: default_p2p_partial_payment_rate(),
2753            payment_correction_rate: default_p2p_payment_correction_rate(),
2754        }
2755    }
2756}
2757
2758/// Distribution of late payment days for P2P.
2759#[derive(Debug, Clone, Serialize, Deserialize)]
2760pub struct LatePaymentDaysDistribution {
2761    /// 1-7 days late (slightly late)
2762    #[serde(default = "default_slightly_late")]
2763    pub slightly_late_1_to_7: f64,
2764    /// 8-14 days late
2765    #[serde(default = "default_late_8_14")]
2766    pub late_8_to_14: f64,
2767    /// 15-30 days late (very late)
2768    #[serde(default = "default_very_late")]
2769    pub very_late_15_to_30: f64,
2770    /// 31-60 days late (severely late)
2771    #[serde(default = "default_severely_late")]
2772    pub severely_late_31_to_60: f64,
2773    /// Over 60 days late (extremely late)
2774    #[serde(default = "default_extremely_late")]
2775    pub extremely_late_over_60: f64,
2776}
2777
2778fn default_slightly_late() -> f64 {
2779    0.50
2780}
2781
2782fn default_late_8_14() -> f64 {
2783    0.25
2784}
2785
2786fn default_very_late() -> f64 {
2787    0.15
2788}
2789
2790fn default_severely_late() -> f64 {
2791    0.07
2792}
2793
2794fn default_extremely_late() -> f64 {
2795    0.03
2796}
2797
2798impl Default for LatePaymentDaysDistribution {
2799    fn default() -> Self {
2800        Self {
2801            slightly_late_1_to_7: default_slightly_late(),
2802            late_8_to_14: default_late_8_14(),
2803            very_late_15_to_30: default_very_late(),
2804            severely_late_31_to_60: default_severely_late(),
2805            extremely_late_over_60: default_extremely_late(),
2806        }
2807    }
2808}
2809
2810/// O2C (Order-to-Cash) flow configuration.
2811#[derive(Debug, Clone, Serialize, Deserialize)]
2812pub struct O2CFlowConfig {
2813    /// Enable O2C document flow generation
2814    #[serde(default = "default_true")]
2815    pub enabled: bool,
2816    /// Credit check failure rate
2817    #[serde(default = "default_credit_check_failure_rate")]
2818    pub credit_check_failure_rate: f64,
2819    /// Rate of partial shipments
2820    #[serde(default = "default_partial_shipment_rate")]
2821    pub partial_shipment_rate: f64,
2822    /// Rate of returns
2823    #[serde(default = "default_return_rate")]
2824    pub return_rate: f64,
2825    /// Bad debt write-off rate
2826    #[serde(default = "default_bad_debt_rate")]
2827    pub bad_debt_rate: f64,
2828    /// Average days from SO to delivery
2829    #[serde(default = "default_so_to_delivery_days")]
2830    pub average_so_to_delivery_days: u32,
2831    /// Average days from delivery to invoice
2832    #[serde(default = "default_delivery_to_invoice_days")]
2833    pub average_delivery_to_invoice_days: u32,
2834    /// Average days from invoice to receipt
2835    #[serde(default = "default_invoice_to_receipt_days")]
2836    pub average_invoice_to_receipt_days: u32,
2837    /// SO line count distribution
2838    #[serde(default)]
2839    pub line_count_distribution: DocumentLineCountDistribution,
2840    /// Cash discount configuration
2841    #[serde(default)]
2842    pub cash_discount: CashDiscountConfig,
2843    /// Payment behavior configuration
2844    #[serde(default)]
2845    pub payment_behavior: O2CPaymentBehaviorConfig,
2846}
2847
2848fn default_credit_check_failure_rate() -> f64 {
2849    0.02
2850}
2851
2852fn default_partial_shipment_rate() -> f64 {
2853    0.10
2854}
2855
2856fn default_return_rate() -> f64 {
2857    0.03
2858}
2859
2860fn default_bad_debt_rate() -> f64 {
2861    0.01
2862}
2863
2864fn default_so_to_delivery_days() -> u32 {
2865    7
2866}
2867
2868fn default_delivery_to_invoice_days() -> u32 {
2869    1
2870}
2871
2872fn default_invoice_to_receipt_days() -> u32 {
2873    45
2874}
2875
2876impl Default for O2CFlowConfig {
2877    fn default() -> Self {
2878        Self {
2879            enabled: true,
2880            credit_check_failure_rate: default_credit_check_failure_rate(),
2881            partial_shipment_rate: default_partial_shipment_rate(),
2882            return_rate: default_return_rate(),
2883            bad_debt_rate: default_bad_debt_rate(),
2884            average_so_to_delivery_days: default_so_to_delivery_days(),
2885            average_delivery_to_invoice_days: default_delivery_to_invoice_days(),
2886            average_invoice_to_receipt_days: default_invoice_to_receipt_days(),
2887            line_count_distribution: DocumentLineCountDistribution::default(),
2888            cash_discount: CashDiscountConfig::default(),
2889            payment_behavior: O2CPaymentBehaviorConfig::default(),
2890        }
2891    }
2892}
2893
2894// ============================================================================
2895// O2C Payment Behavior Configuration
2896// ============================================================================
2897
2898/// O2C payment behavior configuration.
2899#[derive(Debug, Clone, Serialize, Deserialize, Default)]
2900pub struct O2CPaymentBehaviorConfig {
2901    /// Dunning (Mahnung) configuration
2902    #[serde(default)]
2903    pub dunning: DunningConfig,
2904    /// Partial payment configuration
2905    #[serde(default)]
2906    pub partial_payments: PartialPaymentConfig,
2907    /// Short payment configuration (unauthorized deductions)
2908    #[serde(default)]
2909    pub short_payments: ShortPaymentConfig,
2910    /// On-account payment configuration (unapplied payments)
2911    #[serde(default)]
2912    pub on_account_payments: OnAccountPaymentConfig,
2913    /// Payment correction configuration (NSF, chargebacks)
2914    #[serde(default)]
2915    pub payment_corrections: PaymentCorrectionConfig,
2916}
2917
2918/// Dunning (Mahnungen) configuration for AR collections.
2919#[derive(Debug, Clone, Serialize, Deserialize)]
2920pub struct DunningConfig {
2921    /// Enable dunning process
2922    #[serde(default)]
2923    pub enabled: bool,
2924    /// Days overdue for level 1 dunning (1st reminder)
2925    #[serde(default = "default_dunning_level_1_days")]
2926    pub level_1_days_overdue: u32,
2927    /// Days overdue for level 2 dunning (2nd reminder)
2928    #[serde(default = "default_dunning_level_2_days")]
2929    pub level_2_days_overdue: u32,
2930    /// Days overdue for level 3 dunning (final notice)
2931    #[serde(default = "default_dunning_level_3_days")]
2932    pub level_3_days_overdue: u32,
2933    /// Days overdue for collection handover
2934    #[serde(default = "default_collection_days")]
2935    pub collection_days_overdue: u32,
2936    /// Payment rates after each dunning level
2937    #[serde(default)]
2938    pub payment_after_dunning_rates: DunningPaymentRates,
2939    /// Rate of invoices blocked from dunning (disputes)
2940    #[serde(default = "default_dunning_block_rate")]
2941    pub dunning_block_rate: f64,
2942    /// Interest rate per year for overdue amounts
2943    #[serde(default = "default_dunning_interest_rate")]
2944    pub interest_rate_per_year: f64,
2945    /// Fixed dunning charge per letter
2946    #[serde(default = "default_dunning_charge")]
2947    pub dunning_charge: f64,
2948}
2949
2950fn default_dunning_level_1_days() -> u32 {
2951    14
2952}
2953
2954fn default_dunning_level_2_days() -> u32 {
2955    28
2956}
2957
2958fn default_dunning_level_3_days() -> u32 {
2959    42
2960}
2961
2962fn default_collection_days() -> u32 {
2963    60
2964}
2965
2966fn default_dunning_block_rate() -> f64 {
2967    0.05
2968}
2969
2970fn default_dunning_interest_rate() -> f64 {
2971    0.09
2972}
2973
2974fn default_dunning_charge() -> f64 {
2975    25.0
2976}
2977
2978impl Default for DunningConfig {
2979    fn default() -> Self {
2980        Self {
2981            enabled: false,
2982            level_1_days_overdue: default_dunning_level_1_days(),
2983            level_2_days_overdue: default_dunning_level_2_days(),
2984            level_3_days_overdue: default_dunning_level_3_days(),
2985            collection_days_overdue: default_collection_days(),
2986            payment_after_dunning_rates: DunningPaymentRates::default(),
2987            dunning_block_rate: default_dunning_block_rate(),
2988            interest_rate_per_year: default_dunning_interest_rate(),
2989            dunning_charge: default_dunning_charge(),
2990        }
2991    }
2992}
2993
2994/// Payment rates after each dunning level.
2995#[derive(Debug, Clone, Serialize, Deserialize)]
2996pub struct DunningPaymentRates {
2997    /// Rate that pays after level 1 reminder
2998    #[serde(default = "default_after_level_1")]
2999    pub after_level_1: f64,
3000    /// Rate that pays after level 2 reminder
3001    #[serde(default = "default_after_level_2")]
3002    pub after_level_2: f64,
3003    /// Rate that pays after level 3 final notice
3004    #[serde(default = "default_after_level_3")]
3005    pub after_level_3: f64,
3006    /// Rate that pays during collection
3007    #[serde(default = "default_during_collection")]
3008    pub during_collection: f64,
3009    /// Rate that never pays (becomes bad debt)
3010    #[serde(default = "default_never_pay")]
3011    pub never_pay: f64,
3012}
3013
3014fn default_after_level_1() -> f64 {
3015    0.40
3016}
3017
3018fn default_after_level_2() -> f64 {
3019    0.30
3020}
3021
3022fn default_after_level_3() -> f64 {
3023    0.15
3024}
3025
3026fn default_during_collection() -> f64 {
3027    0.05
3028}
3029
3030fn default_never_pay() -> f64 {
3031    0.10
3032}
3033
3034impl Default for DunningPaymentRates {
3035    fn default() -> Self {
3036        Self {
3037            after_level_1: default_after_level_1(),
3038            after_level_2: default_after_level_2(),
3039            after_level_3: default_after_level_3(),
3040            during_collection: default_during_collection(),
3041            never_pay: default_never_pay(),
3042        }
3043    }
3044}
3045
3046/// Partial payment configuration.
3047#[derive(Debug, Clone, Serialize, Deserialize)]
3048pub struct PartialPaymentConfig {
3049    /// Rate of invoices paid partially
3050    #[serde(default = "default_partial_payment_rate")]
3051    pub rate: f64,
3052    /// Distribution of partial payment percentages
3053    #[serde(default)]
3054    pub percentage_distribution: PartialPaymentPercentageDistribution,
3055    /// Average days until remainder is paid
3056    #[serde(default = "default_avg_days_until_remainder")]
3057    pub avg_days_until_remainder: u32,
3058}
3059
3060fn default_partial_payment_rate() -> f64 {
3061    0.08
3062}
3063
3064fn default_avg_days_until_remainder() -> u32 {
3065    30
3066}
3067
3068impl Default for PartialPaymentConfig {
3069    fn default() -> Self {
3070        Self {
3071            rate: default_partial_payment_rate(),
3072            percentage_distribution: PartialPaymentPercentageDistribution::default(),
3073            avg_days_until_remainder: default_avg_days_until_remainder(),
3074        }
3075    }
3076}
3077
3078/// Distribution of partial payment percentages.
3079#[derive(Debug, Clone, Serialize, Deserialize)]
3080pub struct PartialPaymentPercentageDistribution {
3081    /// Pay 25% of invoice
3082    #[serde(default = "default_partial_25")]
3083    pub pay_25_percent: f64,
3084    /// Pay 50% of invoice
3085    #[serde(default = "default_partial_50")]
3086    pub pay_50_percent: f64,
3087    /// Pay 75% of invoice
3088    #[serde(default = "default_partial_75")]
3089    pub pay_75_percent: f64,
3090    /// Pay random percentage
3091    #[serde(default = "default_partial_random")]
3092    pub pay_random_percent: f64,
3093}
3094
3095fn default_partial_25() -> f64 {
3096    0.15
3097}
3098
3099fn default_partial_50() -> f64 {
3100    0.50
3101}
3102
3103fn default_partial_75() -> f64 {
3104    0.25
3105}
3106
3107fn default_partial_random() -> f64 {
3108    0.10
3109}
3110
3111impl Default for PartialPaymentPercentageDistribution {
3112    fn default() -> Self {
3113        Self {
3114            pay_25_percent: default_partial_25(),
3115            pay_50_percent: default_partial_50(),
3116            pay_75_percent: default_partial_75(),
3117            pay_random_percent: default_partial_random(),
3118        }
3119    }
3120}
3121
3122/// Short payment configuration (unauthorized deductions).
3123#[derive(Debug, Clone, Serialize, Deserialize)]
3124pub struct ShortPaymentConfig {
3125    /// Rate of payments that are short
3126    #[serde(default = "default_short_payment_rate")]
3127    pub rate: f64,
3128    /// Distribution of short payment reasons
3129    #[serde(default)]
3130    pub reason_distribution: ShortPaymentReasonDistribution,
3131    /// Maximum percentage that can be short
3132    #[serde(default = "default_max_short_percent")]
3133    pub max_short_percent: f64,
3134}
3135
3136fn default_short_payment_rate() -> f64 {
3137    0.03
3138}
3139
3140fn default_max_short_percent() -> f64 {
3141    0.10
3142}
3143
3144impl Default for ShortPaymentConfig {
3145    fn default() -> Self {
3146        Self {
3147            rate: default_short_payment_rate(),
3148            reason_distribution: ShortPaymentReasonDistribution::default(),
3149            max_short_percent: default_max_short_percent(),
3150        }
3151    }
3152}
3153
3154/// Distribution of short payment reasons.
3155#[derive(Debug, Clone, Serialize, Deserialize)]
3156pub struct ShortPaymentReasonDistribution {
3157    /// Pricing dispute
3158    #[serde(default = "default_pricing_dispute")]
3159    pub pricing_dispute: f64,
3160    /// Quality issue
3161    #[serde(default = "default_quality_issue")]
3162    pub quality_issue: f64,
3163    /// Quantity discrepancy
3164    #[serde(default = "default_quantity_discrepancy")]
3165    pub quantity_discrepancy: f64,
3166    /// Unauthorized deduction
3167    #[serde(default = "default_unauthorized_deduction")]
3168    pub unauthorized_deduction: f64,
3169    /// Early payment discount taken incorrectly
3170    #[serde(default = "default_incorrect_discount")]
3171    pub incorrect_discount: f64,
3172}
3173
3174fn default_pricing_dispute() -> f64 {
3175    0.30
3176}
3177
3178fn default_quality_issue() -> f64 {
3179    0.20
3180}
3181
3182fn default_quantity_discrepancy() -> f64 {
3183    0.20
3184}
3185
3186fn default_unauthorized_deduction() -> f64 {
3187    0.15
3188}
3189
3190fn default_incorrect_discount() -> f64 {
3191    0.15
3192}
3193
3194impl Default for ShortPaymentReasonDistribution {
3195    fn default() -> Self {
3196        Self {
3197            pricing_dispute: default_pricing_dispute(),
3198            quality_issue: default_quality_issue(),
3199            quantity_discrepancy: default_quantity_discrepancy(),
3200            unauthorized_deduction: default_unauthorized_deduction(),
3201            incorrect_discount: default_incorrect_discount(),
3202        }
3203    }
3204}
3205
3206/// On-account payment configuration (unapplied payments).
3207#[derive(Debug, Clone, Serialize, Deserialize)]
3208pub struct OnAccountPaymentConfig {
3209    /// Rate of payments that are on-account (unapplied)
3210    #[serde(default = "default_on_account_rate")]
3211    pub rate: f64,
3212    /// Average days until on-account payments are applied
3213    #[serde(default = "default_avg_days_until_applied")]
3214    pub avg_days_until_applied: u32,
3215}
3216
3217fn default_on_account_rate() -> f64 {
3218    0.02
3219}
3220
3221fn default_avg_days_until_applied() -> u32 {
3222    14
3223}
3224
3225impl Default for OnAccountPaymentConfig {
3226    fn default() -> Self {
3227        Self {
3228            rate: default_on_account_rate(),
3229            avg_days_until_applied: default_avg_days_until_applied(),
3230        }
3231    }
3232}
3233
3234/// Payment correction configuration.
3235#[derive(Debug, Clone, Serialize, Deserialize)]
3236pub struct PaymentCorrectionConfig {
3237    /// Rate of payments requiring correction
3238    #[serde(default = "default_payment_correction_rate")]
3239    pub rate: f64,
3240    /// Distribution of correction types
3241    #[serde(default)]
3242    pub type_distribution: PaymentCorrectionTypeDistribution,
3243}
3244
3245fn default_payment_correction_rate() -> f64 {
3246    0.02
3247}
3248
3249impl Default for PaymentCorrectionConfig {
3250    fn default() -> Self {
3251        Self {
3252            rate: default_payment_correction_rate(),
3253            type_distribution: PaymentCorrectionTypeDistribution::default(),
3254        }
3255    }
3256}
3257
3258/// Distribution of payment correction types.
3259#[derive(Debug, Clone, Serialize, Deserialize)]
3260pub struct PaymentCorrectionTypeDistribution {
3261    /// NSF (Non-sufficient funds) / bounced check
3262    #[serde(default = "default_nsf_rate")]
3263    pub nsf: f64,
3264    /// Chargeback
3265    #[serde(default = "default_chargeback_rate")]
3266    pub chargeback: f64,
3267    /// Wrong amount applied
3268    #[serde(default = "default_wrong_amount_rate")]
3269    pub wrong_amount: f64,
3270    /// Wrong customer applied
3271    #[serde(default = "default_wrong_customer_rate")]
3272    pub wrong_customer: f64,
3273    /// Duplicate payment
3274    #[serde(default = "default_duplicate_payment_rate")]
3275    pub duplicate_payment: f64,
3276}
3277
3278fn default_nsf_rate() -> f64 {
3279    0.30
3280}
3281
3282fn default_chargeback_rate() -> f64 {
3283    0.20
3284}
3285
3286fn default_wrong_amount_rate() -> f64 {
3287    0.20
3288}
3289
3290fn default_wrong_customer_rate() -> f64 {
3291    0.15
3292}
3293
3294fn default_duplicate_payment_rate() -> f64 {
3295    0.15
3296}
3297
3298impl Default for PaymentCorrectionTypeDistribution {
3299    fn default() -> Self {
3300        Self {
3301            nsf: default_nsf_rate(),
3302            chargeback: default_chargeback_rate(),
3303            wrong_amount: default_wrong_amount_rate(),
3304            wrong_customer: default_wrong_customer_rate(),
3305            duplicate_payment: default_duplicate_payment_rate(),
3306        }
3307    }
3308}
3309
3310/// Document line count distribution.
3311#[derive(Debug, Clone, Serialize, Deserialize)]
3312pub struct DocumentLineCountDistribution {
3313    /// Minimum number of lines
3314    #[serde(default = "default_min_lines")]
3315    pub min_lines: u32,
3316    /// Maximum number of lines
3317    #[serde(default = "default_max_lines")]
3318    pub max_lines: u32,
3319    /// Most common line count (mode)
3320    #[serde(default = "default_mode_lines")]
3321    pub mode_lines: u32,
3322}
3323
3324fn default_min_lines() -> u32 {
3325    1
3326}
3327
3328fn default_max_lines() -> u32 {
3329    20
3330}
3331
3332fn default_mode_lines() -> u32 {
3333    3
3334}
3335
3336impl Default for DocumentLineCountDistribution {
3337    fn default() -> Self {
3338        Self {
3339            min_lines: default_min_lines(),
3340            max_lines: default_max_lines(),
3341            mode_lines: default_mode_lines(),
3342        }
3343    }
3344}
3345
3346/// Cash discount configuration.
3347#[derive(Debug, Clone, Serialize, Deserialize)]
3348pub struct CashDiscountConfig {
3349    /// Percentage of invoices eligible for cash discount
3350    #[serde(default = "default_discount_eligible_rate")]
3351    pub eligible_rate: f64,
3352    /// Rate at which customers take the discount
3353    #[serde(default = "default_discount_taken_rate")]
3354    pub taken_rate: f64,
3355    /// Standard discount percentage
3356    #[serde(default = "default_discount_percent")]
3357    pub discount_percent: f64,
3358    /// Days within which discount must be taken
3359    #[serde(default = "default_discount_days")]
3360    pub discount_days: u32,
3361}
3362
3363fn default_discount_eligible_rate() -> f64 {
3364    0.30
3365}
3366
3367fn default_discount_taken_rate() -> f64 {
3368    0.60
3369}
3370
3371fn default_discount_percent() -> f64 {
3372    0.02
3373}
3374
3375fn default_discount_days() -> u32 {
3376    10
3377}
3378
3379impl Default for CashDiscountConfig {
3380    fn default() -> Self {
3381        Self {
3382            eligible_rate: default_discount_eligible_rate(),
3383            taken_rate: default_discount_taken_rate(),
3384            discount_percent: default_discount_percent(),
3385            discount_days: default_discount_days(),
3386        }
3387    }
3388}
3389
3390// ============================================================================
3391// Intercompany Configuration
3392// ============================================================================
3393
3394/// Intercompany transaction configuration.
3395#[derive(Debug, Clone, Serialize, Deserialize)]
3396pub struct IntercompanyConfig {
3397    /// Enable intercompany transaction generation
3398    #[serde(default)]
3399    pub enabled: bool,
3400    /// Rate of transactions that are intercompany
3401    #[serde(default = "default_ic_transaction_rate")]
3402    pub ic_transaction_rate: f64,
3403    /// Transfer pricing method
3404    #[serde(default)]
3405    pub transfer_pricing_method: TransferPricingMethod,
3406    /// Transfer pricing markup percentage (for cost-plus)
3407    #[serde(default = "default_markup_percent")]
3408    pub markup_percent: f64,
3409    /// Generate matched IC pairs (offsetting entries)
3410    #[serde(default = "default_true")]
3411    pub generate_matched_pairs: bool,
3412    /// IC transaction type distribution
3413    #[serde(default)]
3414    pub transaction_type_distribution: ICTransactionTypeDistribution,
3415    /// Generate elimination entries for consolidation
3416    #[serde(default)]
3417    pub generate_eliminations: bool,
3418}
3419
3420fn default_ic_transaction_rate() -> f64 {
3421    0.15
3422}
3423
3424fn default_markup_percent() -> f64 {
3425    0.05
3426}
3427
3428impl Default for IntercompanyConfig {
3429    fn default() -> Self {
3430        Self {
3431            enabled: false,
3432            ic_transaction_rate: default_ic_transaction_rate(),
3433            transfer_pricing_method: TransferPricingMethod::default(),
3434            markup_percent: default_markup_percent(),
3435            generate_matched_pairs: true,
3436            transaction_type_distribution: ICTransactionTypeDistribution::default(),
3437            generate_eliminations: false,
3438        }
3439    }
3440}
3441
3442/// Transfer pricing method.
3443#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize)]
3444#[serde(rename_all = "snake_case")]
3445pub enum TransferPricingMethod {
3446    /// Cost plus a markup
3447    #[default]
3448    CostPlus,
3449    /// Comparable uncontrolled price
3450    ComparableUncontrolled,
3451    /// Resale price method
3452    ResalePrice,
3453    /// Transactional net margin method
3454    TransactionalNetMargin,
3455    /// Profit split method
3456    ProfitSplit,
3457}
3458
3459/// IC transaction type distribution.
3460#[derive(Debug, Clone, Serialize, Deserialize)]
3461pub struct ICTransactionTypeDistribution {
3462    /// Goods sales between entities
3463    pub goods_sale: f64,
3464    /// Services provided
3465    pub service_provided: f64,
3466    /// Intercompany loans
3467    pub loan: f64,
3468    /// Dividends
3469    pub dividend: f64,
3470    /// Management fees
3471    pub management_fee: f64,
3472    /// Royalties
3473    pub royalty: f64,
3474    /// Cost sharing
3475    pub cost_sharing: f64,
3476}
3477
3478impl Default for ICTransactionTypeDistribution {
3479    fn default() -> Self {
3480        Self {
3481            goods_sale: 0.35,
3482            service_provided: 0.20,
3483            loan: 0.10,
3484            dividend: 0.05,
3485            management_fee: 0.15,
3486            royalty: 0.10,
3487            cost_sharing: 0.05,
3488        }
3489    }
3490}
3491
3492// ============================================================================
3493// Balance Configuration
3494// ============================================================================
3495
3496/// Balance and trial balance configuration.
3497#[derive(Debug, Clone, Serialize, Deserialize)]
3498pub struct BalanceConfig {
3499    /// Generate opening balances
3500    #[serde(default)]
3501    pub generate_opening_balances: bool,
3502    /// Generate trial balances
3503    #[serde(default = "default_true")]
3504    pub generate_trial_balances: bool,
3505    /// Target gross margin (for revenue/COGS coherence)
3506    #[serde(default = "default_gross_margin")]
3507    pub target_gross_margin: f64,
3508    /// Target DSO (Days Sales Outstanding)
3509    #[serde(default = "default_dso")]
3510    pub target_dso_days: u32,
3511    /// Target DPO (Days Payable Outstanding)
3512    #[serde(default = "default_dpo")]
3513    pub target_dpo_days: u32,
3514    /// Target current ratio
3515    #[serde(default = "default_current_ratio")]
3516    pub target_current_ratio: f64,
3517    /// Target debt-to-equity ratio
3518    #[serde(default = "default_debt_equity")]
3519    pub target_debt_to_equity: f64,
3520    /// Validate balance sheet equation (A = L + E)
3521    #[serde(default = "default_true")]
3522    pub validate_balance_equation: bool,
3523    /// Reconcile subledgers to GL control accounts
3524    #[serde(default = "default_true")]
3525    pub reconcile_subledgers: bool,
3526}
3527
3528fn default_gross_margin() -> f64 {
3529    0.35
3530}
3531
3532fn default_dso() -> u32 {
3533    45
3534}
3535
3536fn default_dpo() -> u32 {
3537    30
3538}
3539
3540fn default_current_ratio() -> f64 {
3541    1.5
3542}
3543
3544fn default_debt_equity() -> f64 {
3545    0.5
3546}
3547
3548impl Default for BalanceConfig {
3549    fn default() -> Self {
3550        Self {
3551            generate_opening_balances: false,
3552            generate_trial_balances: true,
3553            target_gross_margin: default_gross_margin(),
3554            target_dso_days: default_dso(),
3555            target_dpo_days: default_dpo(),
3556            target_current_ratio: default_current_ratio(),
3557            target_debt_to_equity: default_debt_equity(),
3558            validate_balance_equation: true,
3559            reconcile_subledgers: true,
3560        }
3561    }
3562}
3563
3564// ==========================================================================
3565// OCPM (Object-Centric Process Mining) Configuration
3566// ==========================================================================
3567
3568/// OCPM (Object-Centric Process Mining) configuration.
3569///
3570/// Controls generation of OCEL 2.0 compatible event logs with
3571/// many-to-many event-to-object relationships.
3572#[derive(Debug, Clone, Serialize, Deserialize)]
3573pub struct OcpmConfig {
3574    /// Enable OCPM event log generation
3575    #[serde(default)]
3576    pub enabled: bool,
3577
3578    /// Generate lifecycle events (Start/Complete pairs vs atomic events)
3579    #[serde(default = "default_true")]
3580    pub generate_lifecycle_events: bool,
3581
3582    /// Include object-to-object relationships in output
3583    #[serde(default = "default_true")]
3584    pub include_object_relationships: bool,
3585
3586    /// Compute and export process variants
3587    #[serde(default = "default_true")]
3588    pub compute_variants: bool,
3589
3590    /// Maximum variants to track (0 = unlimited)
3591    #[serde(default)]
3592    pub max_variants: usize,
3593
3594    /// P2P process configuration
3595    #[serde(default)]
3596    pub p2p_process: OcpmProcessConfig,
3597
3598    /// O2C process configuration
3599    #[serde(default)]
3600    pub o2c_process: OcpmProcessConfig,
3601
3602    /// Output format configuration
3603    #[serde(default)]
3604    pub output: OcpmOutputConfig,
3605}
3606
3607impl Default for OcpmConfig {
3608    fn default() -> Self {
3609        Self {
3610            enabled: false,
3611            generate_lifecycle_events: true,
3612            include_object_relationships: true,
3613            compute_variants: true,
3614            max_variants: 0,
3615            p2p_process: OcpmProcessConfig::default(),
3616            o2c_process: OcpmProcessConfig::default(),
3617            output: OcpmOutputConfig::default(),
3618        }
3619    }
3620}
3621
3622/// Process-specific OCPM configuration.
3623#[derive(Debug, Clone, Serialize, Deserialize)]
3624pub struct OcpmProcessConfig {
3625    /// Rework probability (0.0-1.0)
3626    #[serde(default = "default_rework_probability")]
3627    pub rework_probability: f64,
3628
3629    /// Skip step probability (0.0-1.0)
3630    #[serde(default = "default_skip_probability")]
3631    pub skip_step_probability: f64,
3632
3633    /// Out-of-order step probability (0.0-1.0)
3634    #[serde(default = "default_out_of_order_probability")]
3635    pub out_of_order_probability: f64,
3636}
3637
3638fn default_rework_probability() -> f64 {
3639    0.05
3640}
3641
3642fn default_skip_probability() -> f64 {
3643    0.02
3644}
3645
3646fn default_out_of_order_probability() -> f64 {
3647    0.03
3648}
3649
3650impl Default for OcpmProcessConfig {
3651    fn default() -> Self {
3652        Self {
3653            rework_probability: default_rework_probability(),
3654            skip_step_probability: default_skip_probability(),
3655            out_of_order_probability: default_out_of_order_probability(),
3656        }
3657    }
3658}
3659
3660/// OCPM output format configuration.
3661#[derive(Debug, Clone, Serialize, Deserialize)]
3662pub struct OcpmOutputConfig {
3663    /// Export OCEL 2.0 JSON format
3664    #[serde(default = "default_true")]
3665    pub ocel_json: bool,
3666
3667    /// Export OCEL 2.0 XML format
3668    #[serde(default)]
3669    pub ocel_xml: bool,
3670
3671    /// Export XES 2.0 XML format (IEEE standard for process mining tools)
3672    #[serde(default)]
3673    pub xes: bool,
3674
3675    /// Include lifecycle transitions in XES output (start/complete pairs)
3676    #[serde(default = "default_true")]
3677    pub xes_include_lifecycle: bool,
3678
3679    /// Include resource attributes in XES output
3680    #[serde(default = "default_true")]
3681    pub xes_include_resources: bool,
3682
3683    /// Export flattened CSV for each object type
3684    #[serde(default = "default_true")]
3685    pub flattened_csv: bool,
3686
3687    /// Export event-object relationship table
3688    #[serde(default = "default_true")]
3689    pub event_object_csv: bool,
3690
3691    /// Export object-object relationship table
3692    #[serde(default = "default_true")]
3693    pub object_relationship_csv: bool,
3694
3695    /// Export process variants summary
3696    #[serde(default = "default_true")]
3697    pub variants_csv: bool,
3698
3699    /// Export reference process models (canonical P2P, O2C, R2R)
3700    #[serde(default)]
3701    pub export_reference_models: bool,
3702}
3703
3704impl Default for OcpmOutputConfig {
3705    fn default() -> Self {
3706        Self {
3707            ocel_json: true,
3708            ocel_xml: false,
3709            xes: false,
3710            xes_include_lifecycle: true,
3711            xes_include_resources: true,
3712            flattened_csv: true,
3713            event_object_csv: true,
3714            object_relationship_csv: true,
3715            variants_csv: true,
3716            export_reference_models: false,
3717        }
3718    }
3719}
3720
3721/// Audit engagement and workpaper generation configuration.
3722#[derive(Debug, Clone, Serialize, Deserialize)]
3723pub struct AuditGenerationConfig {
3724    /// Enable audit engagement generation
3725    #[serde(default)]
3726    pub enabled: bool,
3727
3728    /// Generate engagement documents and workpapers
3729    #[serde(default = "default_true")]
3730    pub generate_workpapers: bool,
3731
3732    /// Default engagement type distribution
3733    #[serde(default)]
3734    pub engagement_types: AuditEngagementTypesConfig,
3735
3736    /// Workpaper configuration
3737    #[serde(default)]
3738    pub workpapers: WorkpaperConfig,
3739
3740    /// Team configuration
3741    #[serde(default)]
3742    pub team: AuditTeamConfig,
3743
3744    /// Review workflow configuration
3745    #[serde(default)]
3746    pub review: ReviewWorkflowConfig,
3747}
3748
3749impl Default for AuditGenerationConfig {
3750    fn default() -> Self {
3751        Self {
3752            enabled: false,
3753            generate_workpapers: true,
3754            engagement_types: AuditEngagementTypesConfig::default(),
3755            workpapers: WorkpaperConfig::default(),
3756            team: AuditTeamConfig::default(),
3757            review: ReviewWorkflowConfig::default(),
3758        }
3759    }
3760}
3761
3762/// Engagement type distribution configuration.
3763#[derive(Debug, Clone, Serialize, Deserialize)]
3764pub struct AuditEngagementTypesConfig {
3765    /// Financial statement audit probability
3766    #[serde(default = "default_financial_audit_prob")]
3767    pub financial_statement: f64,
3768    /// SOX/ICFR audit probability
3769    #[serde(default = "default_sox_audit_prob")]
3770    pub sox_icfr: f64,
3771    /// Integrated audit probability
3772    #[serde(default = "default_integrated_audit_prob")]
3773    pub integrated: f64,
3774    /// Review engagement probability
3775    #[serde(default = "default_review_prob")]
3776    pub review: f64,
3777    /// Agreed-upon procedures probability
3778    #[serde(default = "default_aup_prob")]
3779    pub agreed_upon_procedures: f64,
3780}
3781
3782fn default_financial_audit_prob() -> f64 {
3783    0.40
3784}
3785fn default_sox_audit_prob() -> f64 {
3786    0.20
3787}
3788fn default_integrated_audit_prob() -> f64 {
3789    0.25
3790}
3791fn default_review_prob() -> f64 {
3792    0.10
3793}
3794fn default_aup_prob() -> f64 {
3795    0.05
3796}
3797
3798impl Default for AuditEngagementTypesConfig {
3799    fn default() -> Self {
3800        Self {
3801            financial_statement: default_financial_audit_prob(),
3802            sox_icfr: default_sox_audit_prob(),
3803            integrated: default_integrated_audit_prob(),
3804            review: default_review_prob(),
3805            agreed_upon_procedures: default_aup_prob(),
3806        }
3807    }
3808}
3809
3810/// Workpaper generation configuration.
3811#[derive(Debug, Clone, Serialize, Deserialize)]
3812pub struct WorkpaperConfig {
3813    /// Average workpapers per engagement phase
3814    #[serde(default = "default_workpapers_per_phase")]
3815    pub average_per_phase: usize,
3816
3817    /// Include ISA compliance references
3818    #[serde(default = "default_true")]
3819    pub include_isa_references: bool,
3820
3821    /// Generate sample details
3822    #[serde(default = "default_true")]
3823    pub include_sample_details: bool,
3824
3825    /// Include cross-references between workpapers
3826    #[serde(default = "default_true")]
3827    pub include_cross_references: bool,
3828
3829    /// Sampling configuration
3830    #[serde(default)]
3831    pub sampling: SamplingConfig,
3832}
3833
3834fn default_workpapers_per_phase() -> usize {
3835    5
3836}
3837
3838impl Default for WorkpaperConfig {
3839    fn default() -> Self {
3840        Self {
3841            average_per_phase: default_workpapers_per_phase(),
3842            include_isa_references: true,
3843            include_sample_details: true,
3844            include_cross_references: true,
3845            sampling: SamplingConfig::default(),
3846        }
3847    }
3848}
3849
3850/// Sampling method configuration.
3851#[derive(Debug, Clone, Serialize, Deserialize)]
3852pub struct SamplingConfig {
3853    /// Statistical sampling rate (0.0-1.0)
3854    #[serde(default = "default_statistical_rate")]
3855    pub statistical_rate: f64,
3856    /// Judgmental sampling rate (0.0-1.0)
3857    #[serde(default = "default_judgmental_rate")]
3858    pub judgmental_rate: f64,
3859    /// Haphazard sampling rate (0.0-1.0)
3860    #[serde(default = "default_haphazard_rate")]
3861    pub haphazard_rate: f64,
3862    /// 100% examination rate (0.0-1.0)
3863    #[serde(default = "default_complete_examination_rate")]
3864    pub complete_examination_rate: f64,
3865}
3866
3867fn default_statistical_rate() -> f64 {
3868    0.40
3869}
3870fn default_judgmental_rate() -> f64 {
3871    0.30
3872}
3873fn default_haphazard_rate() -> f64 {
3874    0.20
3875}
3876fn default_complete_examination_rate() -> f64 {
3877    0.10
3878}
3879
3880impl Default for SamplingConfig {
3881    fn default() -> Self {
3882        Self {
3883            statistical_rate: default_statistical_rate(),
3884            judgmental_rate: default_judgmental_rate(),
3885            haphazard_rate: default_haphazard_rate(),
3886            complete_examination_rate: default_complete_examination_rate(),
3887        }
3888    }
3889}
3890
3891/// Audit team configuration.
3892#[derive(Debug, Clone, Serialize, Deserialize)]
3893pub struct AuditTeamConfig {
3894    /// Minimum team size
3895    #[serde(default = "default_min_team_size")]
3896    pub min_team_size: usize,
3897    /// Maximum team size
3898    #[serde(default = "default_max_team_size")]
3899    pub max_team_size: usize,
3900    /// Probability of having a specialist on the team
3901    #[serde(default = "default_specialist_probability")]
3902    pub specialist_probability: f64,
3903}
3904
3905fn default_min_team_size() -> usize {
3906    3
3907}
3908fn default_max_team_size() -> usize {
3909    8
3910}
3911fn default_specialist_probability() -> f64 {
3912    0.30
3913}
3914
3915impl Default for AuditTeamConfig {
3916    fn default() -> Self {
3917        Self {
3918            min_team_size: default_min_team_size(),
3919            max_team_size: default_max_team_size(),
3920            specialist_probability: default_specialist_probability(),
3921        }
3922    }
3923}
3924
3925/// Review workflow configuration.
3926#[derive(Debug, Clone, Serialize, Deserialize)]
3927pub struct ReviewWorkflowConfig {
3928    /// Average days between preparer completion and first review
3929    #[serde(default = "default_review_delay_days")]
3930    pub average_review_delay_days: u32,
3931    /// Probability of review notes requiring rework
3932    #[serde(default = "default_rework_probability_review")]
3933    pub rework_probability: f64,
3934    /// Require partner sign-off for all workpapers
3935    #[serde(default = "default_true")]
3936    pub require_partner_signoff: bool,
3937}
3938
3939fn default_review_delay_days() -> u32 {
3940    2
3941}
3942fn default_rework_probability_review() -> f64 {
3943    0.15
3944}
3945
3946impl Default for ReviewWorkflowConfig {
3947    fn default() -> Self {
3948        Self {
3949            average_review_delay_days: default_review_delay_days(),
3950            rework_probability: default_rework_probability_review(),
3951            require_partner_signoff: true,
3952        }
3953    }
3954}
3955
3956// =============================================================================
3957// Data Quality Configuration
3958// =============================================================================
3959
3960/// Data quality variation settings for realistic flakiness injection.
3961#[derive(Debug, Clone, Serialize, Deserialize)]
3962pub struct DataQualitySchemaConfig {
3963    /// Enable data quality variations
3964    #[serde(default)]
3965    pub enabled: bool,
3966    /// Preset to use (overrides individual settings if set)
3967    #[serde(default)]
3968    pub preset: DataQualityPreset,
3969    /// Missing value injection settings
3970    #[serde(default)]
3971    pub missing_values: MissingValuesSchemaConfig,
3972    /// Typo injection settings
3973    #[serde(default)]
3974    pub typos: TypoSchemaConfig,
3975    /// Format variation settings
3976    #[serde(default)]
3977    pub format_variations: FormatVariationSchemaConfig,
3978    /// Duplicate injection settings
3979    #[serde(default)]
3980    pub duplicates: DuplicateSchemaConfig,
3981    /// Encoding issue settings
3982    #[serde(default)]
3983    pub encoding_issues: EncodingIssueSchemaConfig,
3984    /// Generate quality issue labels for ML training
3985    #[serde(default)]
3986    pub generate_labels: bool,
3987    /// Per-sink quality profiles (different settings for CSV vs JSON etc.)
3988    #[serde(default)]
3989    pub sink_profiles: SinkQualityProfiles,
3990}
3991
3992impl Default for DataQualitySchemaConfig {
3993    fn default() -> Self {
3994        Self {
3995            enabled: false,
3996            preset: DataQualityPreset::None,
3997            missing_values: MissingValuesSchemaConfig::default(),
3998            typos: TypoSchemaConfig::default(),
3999            format_variations: FormatVariationSchemaConfig::default(),
4000            duplicates: DuplicateSchemaConfig::default(),
4001            encoding_issues: EncodingIssueSchemaConfig::default(),
4002            generate_labels: true,
4003            sink_profiles: SinkQualityProfiles::default(),
4004        }
4005    }
4006}
4007
4008impl DataQualitySchemaConfig {
4009    /// Creates a config for a specific preset profile.
4010    pub fn with_preset(preset: DataQualityPreset) -> Self {
4011        let mut config = Self {
4012            preset,
4013            ..Default::default()
4014        };
4015        config.apply_preset();
4016        config
4017    }
4018
4019    /// Applies the preset settings to the individual configuration fields.
4020    /// Call this after deserializing if preset is not Custom or None.
4021    pub fn apply_preset(&mut self) {
4022        if !self.preset.overrides_settings() {
4023            return;
4024        }
4025
4026        self.enabled = true;
4027
4028        // Missing values
4029        self.missing_values.enabled = self.preset.missing_rate() > 0.0;
4030        self.missing_values.rate = self.preset.missing_rate();
4031
4032        // Typos
4033        self.typos.enabled = self.preset.typo_rate() > 0.0;
4034        self.typos.char_error_rate = self.preset.typo_rate();
4035
4036        // Duplicates
4037        self.duplicates.enabled = self.preset.duplicate_rate() > 0.0;
4038        self.duplicates.exact_duplicate_ratio = self.preset.duplicate_rate() * 0.4;
4039        self.duplicates.near_duplicate_ratio = self.preset.duplicate_rate() * 0.4;
4040        self.duplicates.fuzzy_duplicate_ratio = self.preset.duplicate_rate() * 0.2;
4041
4042        // Format variations
4043        self.format_variations.enabled = self.preset.format_variations_enabled();
4044
4045        // Encoding issues
4046        self.encoding_issues.enabled = self.preset.encoding_issues_enabled();
4047        self.encoding_issues.rate = self.preset.encoding_issue_rate();
4048
4049        // OCR errors for typos in legacy preset
4050        if self.preset.ocr_errors_enabled() {
4051            self.typos.type_weights.ocr_errors = 0.3;
4052        }
4053    }
4054
4055    /// Returns the effective missing value rate (considering preset).
4056    pub fn effective_missing_rate(&self) -> f64 {
4057        if self.preset.overrides_settings() {
4058            self.preset.missing_rate()
4059        } else {
4060            self.missing_values.rate
4061        }
4062    }
4063
4064    /// Returns the effective typo rate (considering preset).
4065    pub fn effective_typo_rate(&self) -> f64 {
4066        if self.preset.overrides_settings() {
4067            self.preset.typo_rate()
4068        } else {
4069            self.typos.char_error_rate
4070        }
4071    }
4072
4073    /// Returns the effective duplicate rate (considering preset).
4074    pub fn effective_duplicate_rate(&self) -> f64 {
4075        if self.preset.overrides_settings() {
4076            self.preset.duplicate_rate()
4077        } else {
4078            self.duplicates.exact_duplicate_ratio
4079                + self.duplicates.near_duplicate_ratio
4080                + self.duplicates.fuzzy_duplicate_ratio
4081        }
4082    }
4083
4084    /// Creates a clean profile config.
4085    pub fn clean() -> Self {
4086        Self::with_preset(DataQualityPreset::Clean)
4087    }
4088
4089    /// Creates a noisy profile config.
4090    pub fn noisy() -> Self {
4091        Self::with_preset(DataQualityPreset::Noisy)
4092    }
4093
4094    /// Creates a legacy profile config.
4095    pub fn legacy() -> Self {
4096        Self::with_preset(DataQualityPreset::Legacy)
4097    }
4098}
4099
4100/// Preset configurations for common data quality scenarios.
4101#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
4102#[serde(rename_all = "snake_case")]
4103pub enum DataQualityPreset {
4104    /// No data quality variations (clean data)
4105    #[default]
4106    None,
4107    /// Minimal variations (very clean data with rare issues)
4108    Minimal,
4109    /// Normal variations (realistic enterprise data quality)
4110    Normal,
4111    /// High variations (messy data for stress testing)
4112    High,
4113    /// Custom (use individual settings)
4114    Custom,
4115
4116    // ========================================
4117    // ML-Oriented Profiles (Phase 2.1)
4118    // ========================================
4119    /// Clean profile for ML training - minimal data quality issues
4120    /// Missing: 0.1%, Typos: 0.05%, Duplicates: 0%, Format: None
4121    Clean,
4122    /// Noisy profile simulating typical production data issues
4123    /// Missing: 5%, Typos: 2%, Duplicates: 1%, Format: Medium
4124    Noisy,
4125    /// Legacy profile simulating migrated/OCR'd historical data
4126    /// Missing: 10%, Typos: 5%, Duplicates: 3%, Format: Heavy + OCR
4127    Legacy,
4128}
4129
4130impl DataQualityPreset {
4131    /// Returns the missing value rate for this preset.
4132    pub fn missing_rate(&self) -> f64 {
4133        match self {
4134            DataQualityPreset::None => 0.0,
4135            DataQualityPreset::Minimal => 0.005,
4136            DataQualityPreset::Normal => 0.02,
4137            DataQualityPreset::High => 0.08,
4138            DataQualityPreset::Custom => 0.01, // Use config value
4139            DataQualityPreset::Clean => 0.001,
4140            DataQualityPreset::Noisy => 0.05,
4141            DataQualityPreset::Legacy => 0.10,
4142        }
4143    }
4144
4145    /// Returns the typo rate for this preset.
4146    pub fn typo_rate(&self) -> f64 {
4147        match self {
4148            DataQualityPreset::None => 0.0,
4149            DataQualityPreset::Minimal => 0.0005,
4150            DataQualityPreset::Normal => 0.002,
4151            DataQualityPreset::High => 0.01,
4152            DataQualityPreset::Custom => 0.001, // Use config value
4153            DataQualityPreset::Clean => 0.0005,
4154            DataQualityPreset::Noisy => 0.02,
4155            DataQualityPreset::Legacy => 0.05,
4156        }
4157    }
4158
4159    /// Returns the duplicate rate for this preset.
4160    pub fn duplicate_rate(&self) -> f64 {
4161        match self {
4162            DataQualityPreset::None => 0.0,
4163            DataQualityPreset::Minimal => 0.001,
4164            DataQualityPreset::Normal => 0.005,
4165            DataQualityPreset::High => 0.02,
4166            DataQualityPreset::Custom => 0.0, // Use config value
4167            DataQualityPreset::Clean => 0.0,
4168            DataQualityPreset::Noisy => 0.01,
4169            DataQualityPreset::Legacy => 0.03,
4170        }
4171    }
4172
4173    /// Returns whether format variations are enabled for this preset.
4174    pub fn format_variations_enabled(&self) -> bool {
4175        match self {
4176            DataQualityPreset::None | DataQualityPreset::Clean => false,
4177            DataQualityPreset::Minimal => true,
4178            DataQualityPreset::Normal => true,
4179            DataQualityPreset::High => true,
4180            DataQualityPreset::Custom => true,
4181            DataQualityPreset::Noisy => true,
4182            DataQualityPreset::Legacy => true,
4183        }
4184    }
4185
4186    /// Returns whether OCR-style errors are enabled for this preset.
4187    pub fn ocr_errors_enabled(&self) -> bool {
4188        matches!(self, DataQualityPreset::Legacy | DataQualityPreset::High)
4189    }
4190
4191    /// Returns whether encoding issues are enabled for this preset.
4192    pub fn encoding_issues_enabled(&self) -> bool {
4193        matches!(
4194            self,
4195            DataQualityPreset::Legacy | DataQualityPreset::High | DataQualityPreset::Noisy
4196        )
4197    }
4198
4199    /// Returns the encoding issue rate for this preset.
4200    pub fn encoding_issue_rate(&self) -> f64 {
4201        match self {
4202            DataQualityPreset::None | DataQualityPreset::Clean | DataQualityPreset::Minimal => 0.0,
4203            DataQualityPreset::Normal => 0.002,
4204            DataQualityPreset::High => 0.01,
4205            DataQualityPreset::Custom => 0.0,
4206            DataQualityPreset::Noisy => 0.005,
4207            DataQualityPreset::Legacy => 0.02,
4208        }
4209    }
4210
4211    /// Returns true if this preset overrides individual settings.
4212    pub fn overrides_settings(&self) -> bool {
4213        !matches!(self, DataQualityPreset::Custom | DataQualityPreset::None)
4214    }
4215
4216    /// Returns a human-readable description of this preset.
4217    pub fn description(&self) -> &'static str {
4218        match self {
4219            DataQualityPreset::None => "No data quality issues (pristine data)",
4220            DataQualityPreset::Minimal => "Very rare data quality issues",
4221            DataQualityPreset::Normal => "Realistic enterprise data quality",
4222            DataQualityPreset::High => "Messy data for stress testing",
4223            DataQualityPreset::Custom => "Custom settings from configuration",
4224            DataQualityPreset::Clean => "ML-ready clean data with minimal issues",
4225            DataQualityPreset::Noisy => "Typical production data with moderate issues",
4226            DataQualityPreset::Legacy => "Legacy/migrated data with heavy issues and OCR errors",
4227        }
4228    }
4229}
4230
4231/// Missing value injection configuration.
4232#[derive(Debug, Clone, Serialize, Deserialize)]
4233pub struct MissingValuesSchemaConfig {
4234    /// Enable missing value injection
4235    #[serde(default)]
4236    pub enabled: bool,
4237    /// Global missing rate (0.0 to 1.0)
4238    #[serde(default = "default_missing_rate")]
4239    pub rate: f64,
4240    /// Missing value strategy
4241    #[serde(default)]
4242    pub strategy: MissingValueStrategy,
4243    /// Field-specific rates (field name -> rate)
4244    #[serde(default)]
4245    pub field_rates: std::collections::HashMap<String, f64>,
4246    /// Fields that should never have missing values
4247    #[serde(default)]
4248    pub protected_fields: Vec<String>,
4249}
4250
4251fn default_missing_rate() -> f64 {
4252    0.01
4253}
4254
4255impl Default for MissingValuesSchemaConfig {
4256    fn default() -> Self {
4257        Self {
4258            enabled: false,
4259            rate: default_missing_rate(),
4260            strategy: MissingValueStrategy::Mcar,
4261            field_rates: std::collections::HashMap::new(),
4262            protected_fields: vec![
4263                "document_id".to_string(),
4264                "company_code".to_string(),
4265                "posting_date".to_string(),
4266            ],
4267        }
4268    }
4269}
4270
4271/// Missing value strategy types.
4272#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
4273#[serde(rename_all = "snake_case")]
4274pub enum MissingValueStrategy {
4275    /// Missing Completely At Random - equal probability for all values
4276    #[default]
4277    Mcar,
4278    /// Missing At Random - depends on other observed values
4279    Mar,
4280    /// Missing Not At Random - depends on the value itself
4281    Mnar,
4282    /// Systematic - entire field groups missing together
4283    Systematic,
4284}
4285
4286/// Typo injection configuration.
4287#[derive(Debug, Clone, Serialize, Deserialize)]
4288pub struct TypoSchemaConfig {
4289    /// Enable typo injection
4290    #[serde(default)]
4291    pub enabled: bool,
4292    /// Character error rate (per character, not per field)
4293    #[serde(default = "default_typo_rate")]
4294    pub char_error_rate: f64,
4295    /// Typo type weights
4296    #[serde(default)]
4297    pub type_weights: TypoTypeWeights,
4298    /// Fields that should never have typos
4299    #[serde(default)]
4300    pub protected_fields: Vec<String>,
4301}
4302
4303fn default_typo_rate() -> f64 {
4304    0.001
4305}
4306
4307impl Default for TypoSchemaConfig {
4308    fn default() -> Self {
4309        Self {
4310            enabled: false,
4311            char_error_rate: default_typo_rate(),
4312            type_weights: TypoTypeWeights::default(),
4313            protected_fields: vec![
4314                "document_id".to_string(),
4315                "gl_account".to_string(),
4316                "company_code".to_string(),
4317            ],
4318        }
4319    }
4320}
4321
4322/// Weights for different typo types.
4323#[derive(Debug, Clone, Serialize, Deserialize)]
4324pub struct TypoTypeWeights {
4325    /// Keyboard-adjacent substitution (e.g., 'a' -> 's')
4326    #[serde(default = "default_substitution_weight")]
4327    pub substitution: f64,
4328    /// Adjacent character transposition (e.g., 'ab' -> 'ba')
4329    #[serde(default = "default_transposition_weight")]
4330    pub transposition: f64,
4331    /// Character insertion
4332    #[serde(default = "default_insertion_weight")]
4333    pub insertion: f64,
4334    /// Character deletion
4335    #[serde(default = "default_deletion_weight")]
4336    pub deletion: f64,
4337    /// OCR-style errors (e.g., '0' -> 'O')
4338    #[serde(default = "default_ocr_weight")]
4339    pub ocr_errors: f64,
4340    /// Homophone substitution (e.g., 'their' -> 'there')
4341    #[serde(default = "default_homophone_weight")]
4342    pub homophones: f64,
4343}
4344
4345fn default_substitution_weight() -> f64 {
4346    0.35
4347}
4348fn default_transposition_weight() -> f64 {
4349    0.25
4350}
4351fn default_insertion_weight() -> f64 {
4352    0.10
4353}
4354fn default_deletion_weight() -> f64 {
4355    0.15
4356}
4357fn default_ocr_weight() -> f64 {
4358    0.10
4359}
4360fn default_homophone_weight() -> f64 {
4361    0.05
4362}
4363
4364impl Default for TypoTypeWeights {
4365    fn default() -> Self {
4366        Self {
4367            substitution: default_substitution_weight(),
4368            transposition: default_transposition_weight(),
4369            insertion: default_insertion_weight(),
4370            deletion: default_deletion_weight(),
4371            ocr_errors: default_ocr_weight(),
4372            homophones: default_homophone_weight(),
4373        }
4374    }
4375}
4376
4377/// Format variation configuration.
4378#[derive(Debug, Clone, Serialize, Deserialize, Default)]
4379pub struct FormatVariationSchemaConfig {
4380    /// Enable format variations
4381    #[serde(default)]
4382    pub enabled: bool,
4383    /// Date format variation settings
4384    #[serde(default)]
4385    pub dates: DateFormatVariationConfig,
4386    /// Amount format variation settings
4387    #[serde(default)]
4388    pub amounts: AmountFormatVariationConfig,
4389    /// Identifier format variation settings
4390    #[serde(default)]
4391    pub identifiers: IdentifierFormatVariationConfig,
4392}
4393
4394/// Date format variation configuration.
4395#[derive(Debug, Clone, Serialize, Deserialize)]
4396pub struct DateFormatVariationConfig {
4397    /// Enable date format variations
4398    #[serde(default)]
4399    pub enabled: bool,
4400    /// Overall variation rate
4401    #[serde(default = "default_date_variation_rate")]
4402    pub rate: f64,
4403    /// Include ISO format (2024-01-15)
4404    #[serde(default = "default_true")]
4405    pub iso_format: bool,
4406    /// Include US format (01/15/2024)
4407    #[serde(default)]
4408    pub us_format: bool,
4409    /// Include EU format (15.01.2024)
4410    #[serde(default)]
4411    pub eu_format: bool,
4412    /// Include long format (January 15, 2024)
4413    #[serde(default)]
4414    pub long_format: bool,
4415}
4416
4417fn default_date_variation_rate() -> f64 {
4418    0.05
4419}
4420
4421impl Default for DateFormatVariationConfig {
4422    fn default() -> Self {
4423        Self {
4424            enabled: false,
4425            rate: default_date_variation_rate(),
4426            iso_format: true,
4427            us_format: false,
4428            eu_format: false,
4429            long_format: false,
4430        }
4431    }
4432}
4433
4434/// Amount format variation configuration.
4435#[derive(Debug, Clone, Serialize, Deserialize)]
4436pub struct AmountFormatVariationConfig {
4437    /// Enable amount format variations
4438    #[serde(default)]
4439    pub enabled: bool,
4440    /// Overall variation rate
4441    #[serde(default = "default_amount_variation_rate")]
4442    pub rate: f64,
4443    /// Include US comma format (1,234.56)
4444    #[serde(default)]
4445    pub us_comma_format: bool,
4446    /// Include EU format (1.234,56)
4447    #[serde(default)]
4448    pub eu_format: bool,
4449    /// Include currency prefix ($1,234.56)
4450    #[serde(default)]
4451    pub currency_prefix: bool,
4452    /// Include accounting format with parentheses for negatives
4453    #[serde(default)]
4454    pub accounting_format: bool,
4455}
4456
4457fn default_amount_variation_rate() -> f64 {
4458    0.02
4459}
4460
4461impl Default for AmountFormatVariationConfig {
4462    fn default() -> Self {
4463        Self {
4464            enabled: false,
4465            rate: default_amount_variation_rate(),
4466            us_comma_format: false,
4467            eu_format: false,
4468            currency_prefix: false,
4469            accounting_format: false,
4470        }
4471    }
4472}
4473
4474/// Identifier format variation configuration.
4475#[derive(Debug, Clone, Serialize, Deserialize)]
4476pub struct IdentifierFormatVariationConfig {
4477    /// Enable identifier format variations
4478    #[serde(default)]
4479    pub enabled: bool,
4480    /// Overall variation rate
4481    #[serde(default = "default_identifier_variation_rate")]
4482    pub rate: f64,
4483    /// Case variations (uppercase, lowercase, mixed)
4484    #[serde(default)]
4485    pub case_variations: bool,
4486    /// Padding variations (leading zeros)
4487    #[serde(default)]
4488    pub padding_variations: bool,
4489    /// Separator variations (dash vs underscore)
4490    #[serde(default)]
4491    pub separator_variations: bool,
4492}
4493
4494fn default_identifier_variation_rate() -> f64 {
4495    0.02
4496}
4497
4498impl Default for IdentifierFormatVariationConfig {
4499    fn default() -> Self {
4500        Self {
4501            enabled: false,
4502            rate: default_identifier_variation_rate(),
4503            case_variations: false,
4504            padding_variations: false,
4505            separator_variations: false,
4506        }
4507    }
4508}
4509
4510/// Duplicate injection configuration.
4511#[derive(Debug, Clone, Serialize, Deserialize)]
4512pub struct DuplicateSchemaConfig {
4513    /// Enable duplicate injection
4514    #[serde(default)]
4515    pub enabled: bool,
4516    /// Overall duplicate rate
4517    #[serde(default = "default_duplicate_rate")]
4518    pub rate: f64,
4519    /// Exact duplicate proportion (out of duplicates)
4520    #[serde(default = "default_exact_duplicate_ratio")]
4521    pub exact_duplicate_ratio: f64,
4522    /// Near duplicate proportion (slight variations)
4523    #[serde(default = "default_near_duplicate_ratio")]
4524    pub near_duplicate_ratio: f64,
4525    /// Fuzzy duplicate proportion (typos in key fields)
4526    #[serde(default = "default_fuzzy_duplicate_ratio")]
4527    pub fuzzy_duplicate_ratio: f64,
4528    /// Maximum date offset for near/fuzzy duplicates (days)
4529    #[serde(default = "default_max_date_offset")]
4530    pub max_date_offset_days: u32,
4531    /// Maximum amount variance for near duplicates (fraction)
4532    #[serde(default = "default_max_amount_variance")]
4533    pub max_amount_variance: f64,
4534}
4535
4536fn default_duplicate_rate() -> f64 {
4537    0.005
4538}
4539fn default_exact_duplicate_ratio() -> f64 {
4540    0.4
4541}
4542fn default_near_duplicate_ratio() -> f64 {
4543    0.35
4544}
4545fn default_fuzzy_duplicate_ratio() -> f64 {
4546    0.25
4547}
4548fn default_max_date_offset() -> u32 {
4549    3
4550}
4551fn default_max_amount_variance() -> f64 {
4552    0.01
4553}
4554
4555impl Default for DuplicateSchemaConfig {
4556    fn default() -> Self {
4557        Self {
4558            enabled: false,
4559            rate: default_duplicate_rate(),
4560            exact_duplicate_ratio: default_exact_duplicate_ratio(),
4561            near_duplicate_ratio: default_near_duplicate_ratio(),
4562            fuzzy_duplicate_ratio: default_fuzzy_duplicate_ratio(),
4563            max_date_offset_days: default_max_date_offset(),
4564            max_amount_variance: default_max_amount_variance(),
4565        }
4566    }
4567}
4568
4569/// Encoding issue configuration.
4570#[derive(Debug, Clone, Serialize, Deserialize)]
4571pub struct EncodingIssueSchemaConfig {
4572    /// Enable encoding issue injection
4573    #[serde(default)]
4574    pub enabled: bool,
4575    /// Overall encoding issue rate
4576    #[serde(default = "default_encoding_rate")]
4577    pub rate: f64,
4578    /// Include mojibake (UTF-8/Latin-1 confusion)
4579    #[serde(default)]
4580    pub mojibake: bool,
4581    /// Include HTML entity corruption
4582    #[serde(default)]
4583    pub html_entities: bool,
4584    /// Include BOM issues
4585    #[serde(default)]
4586    pub bom_issues: bool,
4587}
4588
4589fn default_encoding_rate() -> f64 {
4590    0.001
4591}
4592
4593impl Default for EncodingIssueSchemaConfig {
4594    fn default() -> Self {
4595        Self {
4596            enabled: false,
4597            rate: default_encoding_rate(),
4598            mojibake: false,
4599            html_entities: false,
4600            bom_issues: false,
4601        }
4602    }
4603}
4604
4605/// Per-sink quality profiles for different output formats.
4606#[derive(Debug, Clone, Serialize, Deserialize, Default)]
4607pub struct SinkQualityProfiles {
4608    /// CSV-specific quality settings
4609    #[serde(default)]
4610    pub csv: Option<SinkQualityOverride>,
4611    /// JSON-specific quality settings
4612    #[serde(default)]
4613    pub json: Option<SinkQualityOverride>,
4614    /// Parquet-specific quality settings
4615    #[serde(default)]
4616    pub parquet: Option<SinkQualityOverride>,
4617}
4618
4619/// Quality setting overrides for a specific sink type.
4620#[derive(Debug, Clone, Serialize, Deserialize)]
4621pub struct SinkQualityOverride {
4622    /// Override enabled state
4623    pub enabled: Option<bool>,
4624    /// Override missing value rate
4625    pub missing_rate: Option<f64>,
4626    /// Override typo rate
4627    pub typo_rate: Option<f64>,
4628    /// Override format variation rate
4629    pub format_variation_rate: Option<f64>,
4630    /// Override duplicate rate
4631    pub duplicate_rate: Option<f64>,
4632}
4633
4634// =============================================================================
4635// Accounting Standards Configuration
4636// =============================================================================
4637
4638/// Accounting standards framework configuration for generating standards-compliant data.
4639///
4640/// Supports US GAAP, IFRS, and French GAAP (PCG) frameworks with specific standards:
4641/// - ASC 606/IFRS 15/PCG: Revenue Recognition
4642/// - ASC 842/IFRS 16/PCG: Leases
4643/// - ASC 820/IFRS 13/PCG: Fair Value Measurement
4644/// - ASC 360/IAS 36/PCG: Impairment
4645#[derive(Debug, Clone, Serialize, Deserialize, Default)]
4646pub struct AccountingStandardsConfig {
4647    /// Enable accounting standards generation
4648    #[serde(default)]
4649    pub enabled: bool,
4650
4651    /// Accounting framework to use.
4652    /// When `None`, the country pack's `accounting.framework` is used as fallback;
4653    /// if that is also absent the orchestrator defaults to US GAAP.
4654    #[serde(default, skip_serializing_if = "Option::is_none")]
4655    pub framework: Option<AccountingFrameworkConfig>,
4656
4657    /// Revenue recognition configuration (ASC 606/IFRS 15)
4658    #[serde(default)]
4659    pub revenue_recognition: RevenueRecognitionConfig,
4660
4661    /// Lease accounting configuration (ASC 842/IFRS 16)
4662    #[serde(default)]
4663    pub leases: LeaseAccountingConfig,
4664
4665    /// Fair value measurement configuration (ASC 820/IFRS 13)
4666    #[serde(default)]
4667    pub fair_value: FairValueConfig,
4668
4669    /// Impairment testing configuration (ASC 360/IAS 36)
4670    #[serde(default)]
4671    pub impairment: ImpairmentConfig,
4672
4673    /// Generate framework differences for dual reporting
4674    #[serde(default)]
4675    pub generate_differences: bool,
4676}
4677
4678/// Accounting framework selection.
4679#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
4680#[serde(rename_all = "snake_case")]
4681pub enum AccountingFrameworkConfig {
4682    /// US Generally Accepted Accounting Principles
4683    #[default]
4684    UsGaap,
4685    /// International Financial Reporting Standards
4686    Ifrs,
4687    /// Generate data for both frameworks with reconciliation
4688    DualReporting,
4689    /// French GAAP (Plan Comptable Général – PCG)
4690    FrenchGaap,
4691}
4692
4693/// Revenue recognition configuration (ASC 606/IFRS 15).
4694#[derive(Debug, Clone, Serialize, Deserialize)]
4695pub struct RevenueRecognitionConfig {
4696    /// Enable revenue recognition generation
4697    #[serde(default)]
4698    pub enabled: bool,
4699
4700    /// Generate customer contracts
4701    #[serde(default = "default_true")]
4702    pub generate_contracts: bool,
4703
4704    /// Average number of performance obligations per contract
4705    #[serde(default = "default_avg_obligations")]
4706    pub avg_obligations_per_contract: f64,
4707
4708    /// Rate of contracts with variable consideration
4709    #[serde(default = "default_variable_consideration_rate")]
4710    pub variable_consideration_rate: f64,
4711
4712    /// Rate of over-time revenue recognition (vs point-in-time)
4713    #[serde(default = "default_over_time_rate")]
4714    pub over_time_recognition_rate: f64,
4715
4716    /// Number of contracts to generate
4717    #[serde(default = "default_contract_count")]
4718    pub contract_count: usize,
4719}
4720
4721fn default_avg_obligations() -> f64 {
4722    2.0
4723}
4724
4725fn default_variable_consideration_rate() -> f64 {
4726    0.15
4727}
4728
4729fn default_over_time_rate() -> f64 {
4730    0.30
4731}
4732
4733fn default_contract_count() -> usize {
4734    100
4735}
4736
4737impl Default for RevenueRecognitionConfig {
4738    fn default() -> Self {
4739        Self {
4740            enabled: false,
4741            generate_contracts: true,
4742            avg_obligations_per_contract: default_avg_obligations(),
4743            variable_consideration_rate: default_variable_consideration_rate(),
4744            over_time_recognition_rate: default_over_time_rate(),
4745            contract_count: default_contract_count(),
4746        }
4747    }
4748}
4749
4750/// Lease accounting configuration (ASC 842/IFRS 16).
4751#[derive(Debug, Clone, Serialize, Deserialize)]
4752pub struct LeaseAccountingConfig {
4753    /// Enable lease accounting generation
4754    #[serde(default)]
4755    pub enabled: bool,
4756
4757    /// Number of leases to generate
4758    #[serde(default = "default_lease_count")]
4759    pub lease_count: usize,
4760
4761    /// Percentage of finance leases (vs operating)
4762    #[serde(default = "default_finance_lease_pct")]
4763    pub finance_lease_percent: f64,
4764
4765    /// Average lease term in months
4766    #[serde(default = "default_avg_lease_term")]
4767    pub avg_lease_term_months: u32,
4768
4769    /// Generate amortization schedules
4770    #[serde(default = "default_true")]
4771    pub generate_amortization: bool,
4772
4773    /// Real estate lease percentage
4774    #[serde(default = "default_real_estate_pct")]
4775    pub real_estate_percent: f64,
4776}
4777
4778fn default_lease_count() -> usize {
4779    50
4780}
4781
4782fn default_finance_lease_pct() -> f64 {
4783    0.30
4784}
4785
4786fn default_avg_lease_term() -> u32 {
4787    60
4788}
4789
4790fn default_real_estate_pct() -> f64 {
4791    0.40
4792}
4793
4794impl Default for LeaseAccountingConfig {
4795    fn default() -> Self {
4796        Self {
4797            enabled: false,
4798            lease_count: default_lease_count(),
4799            finance_lease_percent: default_finance_lease_pct(),
4800            avg_lease_term_months: default_avg_lease_term(),
4801            generate_amortization: true,
4802            real_estate_percent: default_real_estate_pct(),
4803        }
4804    }
4805}
4806
4807/// Fair value measurement configuration (ASC 820/IFRS 13).
4808#[derive(Debug, Clone, Serialize, Deserialize)]
4809pub struct FairValueConfig {
4810    /// Enable fair value measurement generation
4811    #[serde(default)]
4812    pub enabled: bool,
4813
4814    /// Number of fair value measurements to generate
4815    #[serde(default = "default_fv_count")]
4816    pub measurement_count: usize,
4817
4818    /// Level 1 (quoted prices) percentage
4819    #[serde(default = "default_level1_pct")]
4820    pub level1_percent: f64,
4821
4822    /// Level 2 (observable inputs) percentage
4823    #[serde(default = "default_level2_pct")]
4824    pub level2_percent: f64,
4825
4826    /// Level 3 (unobservable inputs) percentage
4827    #[serde(default = "default_level3_pct")]
4828    pub level3_percent: f64,
4829
4830    /// Include sensitivity analysis for Level 3
4831    #[serde(default)]
4832    pub include_sensitivity_analysis: bool,
4833}
4834
4835fn default_fv_count() -> usize {
4836    25
4837}
4838
4839fn default_level1_pct() -> f64 {
4840    0.40
4841}
4842
4843fn default_level2_pct() -> f64 {
4844    0.35
4845}
4846
4847fn default_level3_pct() -> f64 {
4848    0.25
4849}
4850
4851impl Default for FairValueConfig {
4852    fn default() -> Self {
4853        Self {
4854            enabled: false,
4855            measurement_count: default_fv_count(),
4856            level1_percent: default_level1_pct(),
4857            level2_percent: default_level2_pct(),
4858            level3_percent: default_level3_pct(),
4859            include_sensitivity_analysis: false,
4860        }
4861    }
4862}
4863
4864/// Impairment testing configuration (ASC 360/IAS 36).
4865#[derive(Debug, Clone, Serialize, Deserialize)]
4866pub struct ImpairmentConfig {
4867    /// Enable impairment testing generation
4868    #[serde(default)]
4869    pub enabled: bool,
4870
4871    /// Number of impairment tests to generate
4872    #[serde(default = "default_impairment_count")]
4873    pub test_count: usize,
4874
4875    /// Rate of tests resulting in impairment
4876    #[serde(default = "default_impairment_rate")]
4877    pub impairment_rate: f64,
4878
4879    /// Generate cash flow projections
4880    #[serde(default = "default_true")]
4881    pub generate_projections: bool,
4882
4883    /// Include goodwill impairment tests
4884    #[serde(default)]
4885    pub include_goodwill: bool,
4886}
4887
4888fn default_impairment_count() -> usize {
4889    15
4890}
4891
4892fn default_impairment_rate() -> f64 {
4893    0.10
4894}
4895
4896impl Default for ImpairmentConfig {
4897    fn default() -> Self {
4898        Self {
4899            enabled: false,
4900            test_count: default_impairment_count(),
4901            impairment_rate: default_impairment_rate(),
4902            generate_projections: true,
4903            include_goodwill: false,
4904        }
4905    }
4906}
4907
4908// =============================================================================
4909// Audit Standards Configuration
4910// =============================================================================
4911
4912/// Audit standards framework configuration for generating standards-compliant audit data.
4913///
4914/// Supports ISA (International Standards on Auditing) and PCAOB standards:
4915/// - ISA 200-720: Complete coverage of audit standards
4916/// - ISA 520: Analytical Procedures
4917/// - ISA 505: External Confirmations
4918/// - ISA 700/705/706/701: Audit Reports
4919/// - PCAOB AS 2201: ICFR Auditing
4920#[derive(Debug, Clone, Serialize, Deserialize, Default)]
4921pub struct AuditStandardsConfig {
4922    /// Enable audit standards generation
4923    #[serde(default)]
4924    pub enabled: bool,
4925
4926    /// ISA compliance configuration
4927    #[serde(default)]
4928    pub isa_compliance: IsaComplianceConfig,
4929
4930    /// Analytical procedures configuration (ISA 520)
4931    #[serde(default)]
4932    pub analytical_procedures: AnalyticalProceduresConfig,
4933
4934    /// External confirmations configuration (ISA 505)
4935    #[serde(default)]
4936    pub confirmations: ConfirmationsConfig,
4937
4938    /// Audit opinion configuration (ISA 700/705/706/701)
4939    #[serde(default)]
4940    pub opinion: AuditOpinionConfig,
4941
4942    /// Generate complete audit trail with traceability
4943    #[serde(default)]
4944    pub generate_audit_trail: bool,
4945
4946    /// SOX 302/404 compliance configuration
4947    #[serde(default)]
4948    pub sox: SoxComplianceConfig,
4949
4950    /// PCAOB-specific configuration
4951    #[serde(default)]
4952    pub pcaob: PcaobConfig,
4953}
4954
4955/// ISA compliance level configuration.
4956#[derive(Debug, Clone, Serialize, Deserialize)]
4957pub struct IsaComplianceConfig {
4958    /// Enable ISA compliance tracking
4959    #[serde(default)]
4960    pub enabled: bool,
4961
4962    /// Compliance level: "basic", "standard", "comprehensive"
4963    #[serde(default = "default_compliance_level")]
4964    pub compliance_level: String,
4965
4966    /// Generate ISA requirement mappings
4967    #[serde(default = "default_true")]
4968    pub generate_isa_mappings: bool,
4969
4970    /// Generate ISA coverage summary
4971    #[serde(default = "default_true")]
4972    pub generate_coverage_summary: bool,
4973
4974    /// Include PCAOB standard mappings (for dual framework)
4975    #[serde(default)]
4976    pub include_pcaob: bool,
4977
4978    /// Framework to use: "isa", "pcaob", "dual"
4979    #[serde(default = "default_audit_framework")]
4980    pub framework: String,
4981}
4982
4983fn default_compliance_level() -> String {
4984    "standard".to_string()
4985}
4986
4987fn default_audit_framework() -> String {
4988    "isa".to_string()
4989}
4990
4991impl Default for IsaComplianceConfig {
4992    fn default() -> Self {
4993        Self {
4994            enabled: false,
4995            compliance_level: default_compliance_level(),
4996            generate_isa_mappings: true,
4997            generate_coverage_summary: true,
4998            include_pcaob: false,
4999            framework: default_audit_framework(),
5000        }
5001    }
5002}
5003
5004/// Analytical procedures configuration (ISA 520).
5005#[derive(Debug, Clone, Serialize, Deserialize)]
5006pub struct AnalyticalProceduresConfig {
5007    /// Enable analytical procedures generation
5008    #[serde(default)]
5009    pub enabled: bool,
5010
5011    /// Number of procedures per account/area
5012    #[serde(default = "default_procedures_per_account")]
5013    pub procedures_per_account: usize,
5014
5015    /// Probability of variance exceeding threshold
5016    #[serde(default = "default_variance_probability")]
5017    pub variance_probability: f64,
5018
5019    /// Include variance investigations
5020    #[serde(default = "default_true")]
5021    pub generate_investigations: bool,
5022
5023    /// Include financial ratio analysis
5024    #[serde(default = "default_true")]
5025    pub include_ratio_analysis: bool,
5026}
5027
5028fn default_procedures_per_account() -> usize {
5029    3
5030}
5031
5032fn default_variance_probability() -> f64 {
5033    0.20
5034}
5035
5036impl Default for AnalyticalProceduresConfig {
5037    fn default() -> Self {
5038        Self {
5039            enabled: false,
5040            procedures_per_account: default_procedures_per_account(),
5041            variance_probability: default_variance_probability(),
5042            generate_investigations: true,
5043            include_ratio_analysis: true,
5044        }
5045    }
5046}
5047
5048/// External confirmations configuration (ISA 505).
5049#[derive(Debug, Clone, Serialize, Deserialize)]
5050pub struct ConfirmationsConfig {
5051    /// Enable confirmation generation
5052    #[serde(default)]
5053    pub enabled: bool,
5054
5055    /// Number of confirmations to generate
5056    #[serde(default = "default_confirmation_count")]
5057    pub confirmation_count: usize,
5058
5059    /// Positive response rate
5060    #[serde(default = "default_positive_response_rate")]
5061    pub positive_response_rate: f64,
5062
5063    /// Exception rate (responses with differences)
5064    #[serde(default = "default_exception_rate_confirm")]
5065    pub exception_rate: f64,
5066
5067    /// Non-response rate
5068    #[serde(default = "default_non_response_rate")]
5069    pub non_response_rate: f64,
5070
5071    /// Generate alternative procedures for non-responses
5072    #[serde(default = "default_true")]
5073    pub generate_alternative_procedures: bool,
5074}
5075
5076fn default_confirmation_count() -> usize {
5077    50
5078}
5079
5080fn default_positive_response_rate() -> f64 {
5081    0.85
5082}
5083
5084fn default_exception_rate_confirm() -> f64 {
5085    0.10
5086}
5087
5088fn default_non_response_rate() -> f64 {
5089    0.05
5090}
5091
5092impl Default for ConfirmationsConfig {
5093    fn default() -> Self {
5094        Self {
5095            enabled: false,
5096            confirmation_count: default_confirmation_count(),
5097            positive_response_rate: default_positive_response_rate(),
5098            exception_rate: default_exception_rate_confirm(),
5099            non_response_rate: default_non_response_rate(),
5100            generate_alternative_procedures: true,
5101        }
5102    }
5103}
5104
5105/// Audit opinion configuration (ISA 700/705/706/701).
5106#[derive(Debug, Clone, Serialize, Deserialize)]
5107pub struct AuditOpinionConfig {
5108    /// Enable audit opinion generation
5109    #[serde(default)]
5110    pub enabled: bool,
5111
5112    /// Generate Key Audit Matters (KAM) / Critical Audit Matters (CAM)
5113    #[serde(default = "default_true")]
5114    pub generate_kam: bool,
5115
5116    /// Average number of KAMs/CAMs per opinion
5117    #[serde(default = "default_kam_count")]
5118    pub average_kam_count: usize,
5119
5120    /// Rate of modified opinions
5121    #[serde(default = "default_modified_opinion_rate")]
5122    pub modified_opinion_rate: f64,
5123
5124    /// Include emphasis of matter paragraphs
5125    #[serde(default)]
5126    pub include_emphasis_of_matter: bool,
5127
5128    /// Include going concern conclusions
5129    #[serde(default = "default_true")]
5130    pub include_going_concern: bool,
5131}
5132
5133fn default_kam_count() -> usize {
5134    3
5135}
5136
5137fn default_modified_opinion_rate() -> f64 {
5138    0.05
5139}
5140
5141impl Default for AuditOpinionConfig {
5142    fn default() -> Self {
5143        Self {
5144            enabled: false,
5145            generate_kam: true,
5146            average_kam_count: default_kam_count(),
5147            modified_opinion_rate: default_modified_opinion_rate(),
5148            include_emphasis_of_matter: false,
5149            include_going_concern: true,
5150        }
5151    }
5152}
5153
5154/// SOX compliance configuration (Sections 302/404).
5155#[derive(Debug, Clone, Serialize, Deserialize)]
5156pub struct SoxComplianceConfig {
5157    /// Enable SOX compliance generation
5158    #[serde(default)]
5159    pub enabled: bool,
5160
5161    /// Generate Section 302 CEO/CFO certifications
5162    #[serde(default = "default_true")]
5163    pub generate_302_certifications: bool,
5164
5165    /// Generate Section 404 ICFR assessments
5166    #[serde(default = "default_true")]
5167    pub generate_404_assessments: bool,
5168
5169    /// Materiality threshold for SOX testing
5170    #[serde(default = "default_sox_materiality_threshold")]
5171    pub materiality_threshold: f64,
5172
5173    /// Rate of material weaknesses
5174    #[serde(default = "default_material_weakness_rate")]
5175    pub material_weakness_rate: f64,
5176
5177    /// Rate of significant deficiencies
5178    #[serde(default = "default_significant_deficiency_rate")]
5179    pub significant_deficiency_rate: f64,
5180}
5181
5182fn default_material_weakness_rate() -> f64 {
5183    0.02
5184}
5185
5186fn default_significant_deficiency_rate() -> f64 {
5187    0.08
5188}
5189
5190impl Default for SoxComplianceConfig {
5191    fn default() -> Self {
5192        Self {
5193            enabled: false,
5194            generate_302_certifications: true,
5195            generate_404_assessments: true,
5196            materiality_threshold: default_sox_materiality_threshold(),
5197            material_weakness_rate: default_material_weakness_rate(),
5198            significant_deficiency_rate: default_significant_deficiency_rate(),
5199        }
5200    }
5201}
5202
5203/// PCAOB-specific configuration.
5204#[derive(Debug, Clone, Serialize, Deserialize)]
5205pub struct PcaobConfig {
5206    /// Enable PCAOB-specific elements
5207    #[serde(default)]
5208    pub enabled: bool,
5209
5210    /// Treat as PCAOB audit (vs ISA-only)
5211    #[serde(default)]
5212    pub is_pcaob_audit: bool,
5213
5214    /// Generate Critical Audit Matters (CAM)
5215    #[serde(default = "default_true")]
5216    pub generate_cam: bool,
5217
5218    /// Include ICFR opinion (for integrated audits)
5219    #[serde(default)]
5220    pub include_icfr_opinion: bool,
5221
5222    /// Generate PCAOB-ISA standard mappings
5223    #[serde(default)]
5224    pub generate_standard_mappings: bool,
5225}
5226
5227impl Default for PcaobConfig {
5228    fn default() -> Self {
5229        Self {
5230            enabled: false,
5231            is_pcaob_audit: false,
5232            generate_cam: true,
5233            include_icfr_opinion: false,
5234            generate_standard_mappings: false,
5235        }
5236    }
5237}
5238
5239// =============================================================================
5240// Advanced Distribution Configuration
5241// =============================================================================
5242
5243/// Advanced distribution configuration for realistic data generation.
5244///
5245/// This section enables sophisticated distribution models including:
5246/// - Mixture models (multi-modal distributions)
5247/// - Cross-field correlations
5248/// - Conditional distributions
5249/// - Regime changes and economic cycles
5250/// - Statistical validation
5251#[derive(Debug, Clone, Serialize, Deserialize, Default)]
5252pub struct AdvancedDistributionConfig {
5253    /// Enable advanced distribution features.
5254    #[serde(default)]
5255    pub enabled: bool,
5256
5257    /// Mixture model configuration for amounts.
5258    #[serde(default)]
5259    pub amounts: MixtureDistributionSchemaConfig,
5260
5261    /// Cross-field correlation configuration.
5262    #[serde(default)]
5263    pub correlations: CorrelationSchemaConfig,
5264
5265    /// Conditional distribution configurations.
5266    #[serde(default)]
5267    pub conditional: Vec<ConditionalDistributionSchemaConfig>,
5268
5269    /// Regime change configuration.
5270    #[serde(default)]
5271    pub regime_changes: RegimeChangeSchemaConfig,
5272
5273    /// Industry-specific distribution profile.
5274    #[serde(default)]
5275    pub industry_profile: Option<IndustryProfileType>,
5276
5277    /// Statistical validation configuration.
5278    #[serde(default)]
5279    pub validation: StatisticalValidationSchemaConfig,
5280}
5281
5282/// Industry profile types for pre-configured distribution settings.
5283#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5284#[serde(rename_all = "snake_case")]
5285pub enum IndustryProfileType {
5286    /// Retail industry profile (POS sales, inventory, seasonal)
5287    Retail,
5288    /// Manufacturing industry profile (raw materials, maintenance, capital)
5289    Manufacturing,
5290    /// Financial services profile (wire transfers, ACH, fee income)
5291    FinancialServices,
5292    /// Healthcare profile (claims, procedures, supplies)
5293    Healthcare,
5294    /// Technology profile (subscriptions, services, R&D)
5295    Technology,
5296}
5297
5298/// Mixture model distribution configuration.
5299#[derive(Debug, Clone, Serialize, Deserialize)]
5300pub struct MixtureDistributionSchemaConfig {
5301    /// Enable mixture model for amount generation.
5302    #[serde(default)]
5303    pub enabled: bool,
5304
5305    /// Distribution type: "gaussian" or "lognormal".
5306    #[serde(default = "default_mixture_type")]
5307    pub distribution_type: MixtureDistributionType,
5308
5309    /// Mixture components with weights.
5310    #[serde(default)]
5311    pub components: Vec<MixtureComponentConfig>,
5312
5313    /// Minimum value constraint.
5314    #[serde(default = "default_min_amount")]
5315    pub min_value: f64,
5316
5317    /// Maximum value constraint (optional).
5318    #[serde(default)]
5319    pub max_value: Option<f64>,
5320
5321    /// Decimal places for rounding.
5322    #[serde(default = "default_decimal_places")]
5323    pub decimal_places: u8,
5324}
5325
5326fn default_mixture_type() -> MixtureDistributionType {
5327    MixtureDistributionType::LogNormal
5328}
5329
5330fn default_min_amount() -> f64 {
5331    0.01
5332}
5333
5334fn default_decimal_places() -> u8 {
5335    2
5336}
5337
5338impl Default for MixtureDistributionSchemaConfig {
5339    fn default() -> Self {
5340        Self {
5341            enabled: false,
5342            distribution_type: MixtureDistributionType::LogNormal,
5343            components: Vec::new(),
5344            min_value: 0.01,
5345            max_value: None,
5346            decimal_places: 2,
5347        }
5348    }
5349}
5350
5351/// Mixture distribution type.
5352#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
5353#[serde(rename_all = "snake_case")]
5354pub enum MixtureDistributionType {
5355    /// Gaussian (normal) mixture
5356    Gaussian,
5357    /// Log-normal mixture (for positive amounts)
5358    #[default]
5359    LogNormal,
5360}
5361
5362/// Configuration for a single mixture component.
5363#[derive(Debug, Clone, Serialize, Deserialize)]
5364pub struct MixtureComponentConfig {
5365    /// Weight of this component (must sum to 1.0 across all components).
5366    pub weight: f64,
5367
5368    /// Location parameter (mean for Gaussian, mu for log-normal).
5369    pub mu: f64,
5370
5371    /// Scale parameter (std dev for Gaussian, sigma for log-normal).
5372    pub sigma: f64,
5373
5374    /// Optional label for this component (e.g., "routine", "significant", "major").
5375    #[serde(default)]
5376    pub label: Option<String>,
5377}
5378
5379/// Cross-field correlation configuration.
5380#[derive(Debug, Clone, Serialize, Deserialize)]
5381pub struct CorrelationSchemaConfig {
5382    /// Enable correlation modeling.
5383    #[serde(default)]
5384    pub enabled: bool,
5385
5386    /// Copula type for dependency modeling.
5387    #[serde(default)]
5388    pub copula_type: CopulaSchemaType,
5389
5390    /// Field definitions for correlation.
5391    #[serde(default)]
5392    pub fields: Vec<CorrelatedFieldConfig>,
5393
5394    /// Correlation matrix (upper triangular, row-major).
5395    /// For n fields, this should have n*(n-1)/2 values.
5396    #[serde(default)]
5397    pub matrix: Vec<f64>,
5398
5399    /// Expected correlations for validation.
5400    #[serde(default)]
5401    pub expected_correlations: Vec<ExpectedCorrelationConfig>,
5402}
5403
5404impl Default for CorrelationSchemaConfig {
5405    fn default() -> Self {
5406        Self {
5407            enabled: false,
5408            copula_type: CopulaSchemaType::Gaussian,
5409            fields: Vec::new(),
5410            matrix: Vec::new(),
5411            expected_correlations: Vec::new(),
5412        }
5413    }
5414}
5415
5416/// Copula type for dependency modeling.
5417#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
5418#[serde(rename_all = "snake_case")]
5419pub enum CopulaSchemaType {
5420    /// Gaussian copula (symmetric, no tail dependence)
5421    #[default]
5422    Gaussian,
5423    /// Clayton copula (lower tail dependence)
5424    Clayton,
5425    /// Gumbel copula (upper tail dependence)
5426    Gumbel,
5427    /// Frank copula (symmetric, no tail dependence)
5428    Frank,
5429    /// Student-t copula (both tail dependencies)
5430    StudentT,
5431}
5432
5433/// Configuration for a correlated field.
5434#[derive(Debug, Clone, Serialize, Deserialize)]
5435pub struct CorrelatedFieldConfig {
5436    /// Field name.
5437    pub name: String,
5438
5439    /// Marginal distribution type.
5440    #[serde(default)]
5441    pub distribution: MarginalDistributionConfig,
5442}
5443
5444/// Marginal distribution configuration.
5445#[derive(Debug, Clone, Serialize, Deserialize)]
5446#[serde(tag = "type", rename_all = "snake_case")]
5447pub enum MarginalDistributionConfig {
5448    /// Normal distribution.
5449    Normal {
5450        /// Mean
5451        mu: f64,
5452        /// Standard deviation
5453        sigma: f64,
5454    },
5455    /// Log-normal distribution.
5456    LogNormal {
5457        /// Location parameter
5458        mu: f64,
5459        /// Scale parameter
5460        sigma: f64,
5461    },
5462    /// Uniform distribution.
5463    Uniform {
5464        /// Minimum value
5465        min: f64,
5466        /// Maximum value
5467        max: f64,
5468    },
5469    /// Discrete uniform distribution.
5470    DiscreteUniform {
5471        /// Minimum integer value
5472        min: i32,
5473        /// Maximum integer value
5474        max: i32,
5475    },
5476}
5477
5478impl Default for MarginalDistributionConfig {
5479    fn default() -> Self {
5480        Self::Normal {
5481            mu: 0.0,
5482            sigma: 1.0,
5483        }
5484    }
5485}
5486
5487/// Expected correlation for validation.
5488#[derive(Debug, Clone, Serialize, Deserialize)]
5489pub struct ExpectedCorrelationConfig {
5490    /// First field name.
5491    pub field1: String,
5492    /// Second field name.
5493    pub field2: String,
5494    /// Expected correlation coefficient.
5495    pub expected_r: f64,
5496    /// Acceptable tolerance.
5497    #[serde(default = "default_correlation_tolerance")]
5498    pub tolerance: f64,
5499}
5500
5501fn default_correlation_tolerance() -> f64 {
5502    0.10
5503}
5504
5505/// Conditional distribution configuration.
5506#[derive(Debug, Clone, Serialize, Deserialize)]
5507pub struct ConditionalDistributionSchemaConfig {
5508    /// Output field name to generate.
5509    pub output_field: String,
5510
5511    /// Input field name that conditions the distribution.
5512    pub input_field: String,
5513
5514    /// Breakpoints defining distribution changes.
5515    #[serde(default)]
5516    pub breakpoints: Vec<ConditionalBreakpointConfig>,
5517
5518    /// Default distribution when below all breakpoints.
5519    #[serde(default)]
5520    pub default_distribution: ConditionalDistributionParamsConfig,
5521
5522    /// Minimum output value constraint.
5523    #[serde(default)]
5524    pub min_value: Option<f64>,
5525
5526    /// Maximum output value constraint.
5527    #[serde(default)]
5528    pub max_value: Option<f64>,
5529
5530    /// Decimal places for output rounding.
5531    #[serde(default = "default_decimal_places")]
5532    pub decimal_places: u8,
5533}
5534
5535/// Breakpoint for conditional distribution.
5536#[derive(Debug, Clone, Serialize, Deserialize)]
5537pub struct ConditionalBreakpointConfig {
5538    /// Input value threshold.
5539    pub threshold: f64,
5540
5541    /// Distribution to use when input >= threshold.
5542    pub distribution: ConditionalDistributionParamsConfig,
5543}
5544
5545/// Distribution parameters for conditional distributions.
5546#[derive(Debug, Clone, Serialize, Deserialize)]
5547#[serde(tag = "type", rename_all = "snake_case")]
5548pub enum ConditionalDistributionParamsConfig {
5549    /// Fixed value.
5550    Fixed {
5551        /// The fixed value
5552        value: f64,
5553    },
5554    /// Normal distribution.
5555    Normal {
5556        /// Mean
5557        mu: f64,
5558        /// Standard deviation
5559        sigma: f64,
5560    },
5561    /// Log-normal distribution.
5562    LogNormal {
5563        /// Location parameter
5564        mu: f64,
5565        /// Scale parameter
5566        sigma: f64,
5567    },
5568    /// Uniform distribution.
5569    Uniform {
5570        /// Minimum
5571        min: f64,
5572        /// Maximum
5573        max: f64,
5574    },
5575    /// Beta distribution (scaled).
5576    Beta {
5577        /// Alpha parameter
5578        alpha: f64,
5579        /// Beta parameter
5580        beta: f64,
5581        /// Minimum output value
5582        min: f64,
5583        /// Maximum output value
5584        max: f64,
5585    },
5586    /// Discrete values with weights.
5587    Discrete {
5588        /// Possible values
5589        values: Vec<f64>,
5590        /// Weights (should sum to 1.0)
5591        weights: Vec<f64>,
5592    },
5593}
5594
5595impl Default for ConditionalDistributionParamsConfig {
5596    fn default() -> Self {
5597        Self::Normal {
5598            mu: 0.0,
5599            sigma: 1.0,
5600        }
5601    }
5602}
5603
5604/// Regime change configuration.
5605#[derive(Debug, Clone, Serialize, Deserialize, Default)]
5606pub struct RegimeChangeSchemaConfig {
5607    /// Enable regime change modeling.
5608    #[serde(default)]
5609    pub enabled: bool,
5610
5611    /// List of regime changes.
5612    #[serde(default)]
5613    pub changes: Vec<RegimeChangeEventConfig>,
5614
5615    /// Economic cycle configuration.
5616    #[serde(default)]
5617    pub economic_cycle: Option<EconomicCycleSchemaConfig>,
5618
5619    /// Parameter drift configurations.
5620    #[serde(default)]
5621    pub parameter_drifts: Vec<ParameterDriftSchemaConfig>,
5622}
5623
5624/// A single regime change event.
5625#[derive(Debug, Clone, Serialize, Deserialize)]
5626pub struct RegimeChangeEventConfig {
5627    /// Date when the change occurs (ISO 8601 format).
5628    pub date: String,
5629
5630    /// Type of regime change.
5631    pub change_type: RegimeChangeTypeConfig,
5632
5633    /// Description of the change.
5634    #[serde(default)]
5635    pub description: Option<String>,
5636
5637    /// Effects of this regime change.
5638    #[serde(default)]
5639    pub effects: Vec<RegimeEffectConfig>,
5640}
5641
5642/// Type of regime change.
5643#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5644#[serde(rename_all = "snake_case")]
5645pub enum RegimeChangeTypeConfig {
5646    /// Acquisition - sudden volume and amount increase
5647    Acquisition,
5648    /// Divestiture - sudden volume and amount decrease
5649    Divestiture,
5650    /// Price increase - amounts increase
5651    PriceIncrease,
5652    /// Price decrease - amounts decrease
5653    PriceDecrease,
5654    /// New product launch - volume ramp-up
5655    ProductLaunch,
5656    /// Product discontinuation - volume ramp-down
5657    ProductDiscontinuation,
5658    /// Policy change - affects patterns
5659    PolicyChange,
5660    /// Competitor entry - market disruption
5661    CompetitorEntry,
5662    /// Custom effect
5663    Custom,
5664}
5665
5666/// Effect of a regime change on a specific field.
5667#[derive(Debug, Clone, Serialize, Deserialize)]
5668pub struct RegimeEffectConfig {
5669    /// Field being affected.
5670    pub field: String,
5671
5672    /// Multiplier to apply (1.0 = no change, 1.5 = 50% increase).
5673    pub multiplier: f64,
5674}
5675
5676/// Economic cycle configuration.
5677#[derive(Debug, Clone, Serialize, Deserialize)]
5678pub struct EconomicCycleSchemaConfig {
5679    /// Enable economic cycle modeling.
5680    #[serde(default)]
5681    pub enabled: bool,
5682
5683    /// Cycle period in months (e.g., 48 for 4-year business cycle).
5684    #[serde(default = "default_cycle_period")]
5685    pub period_months: u32,
5686
5687    /// Amplitude of cycle effect (0.0-1.0).
5688    #[serde(default = "default_cycle_amplitude")]
5689    pub amplitude: f64,
5690
5691    /// Phase offset in months.
5692    #[serde(default)]
5693    pub phase_offset: u32,
5694
5695    /// Recession periods (start_month, duration_months).
5696    #[serde(default)]
5697    pub recessions: Vec<RecessionPeriodConfig>,
5698}
5699
5700fn default_cycle_period() -> u32 {
5701    48
5702}
5703
5704fn default_cycle_amplitude() -> f64 {
5705    0.15
5706}
5707
5708impl Default for EconomicCycleSchemaConfig {
5709    fn default() -> Self {
5710        Self {
5711            enabled: false,
5712            period_months: 48,
5713            amplitude: 0.15,
5714            phase_offset: 0,
5715            recessions: Vec::new(),
5716        }
5717    }
5718}
5719
5720/// Recession period configuration.
5721#[derive(Debug, Clone, Serialize, Deserialize)]
5722pub struct RecessionPeriodConfig {
5723    /// Start month (0-indexed from generation start).
5724    pub start_month: u32,
5725
5726    /// Duration in months.
5727    pub duration_months: u32,
5728
5729    /// Severity (0.0-1.0, affects volume reduction).
5730    #[serde(default = "default_recession_severity")]
5731    pub severity: f64,
5732}
5733
5734fn default_recession_severity() -> f64 {
5735    0.20
5736}
5737
5738/// Parameter drift configuration.
5739#[derive(Debug, Clone, Serialize, Deserialize)]
5740pub struct ParameterDriftSchemaConfig {
5741    /// Parameter being drifted.
5742    pub parameter: String,
5743
5744    /// Drift type.
5745    pub drift_type: ParameterDriftTypeConfig,
5746
5747    /// Start value.
5748    pub start_value: f64,
5749
5750    /// End value.
5751    pub end_value: f64,
5752
5753    /// Start period (month, 0-indexed).
5754    #[serde(default)]
5755    pub start_period: u32,
5756
5757    /// End period (month, optional - defaults to end of generation).
5758    #[serde(default)]
5759    pub end_period: Option<u32>,
5760}
5761
5762/// Parameter drift type.
5763#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
5764#[serde(rename_all = "snake_case")]
5765pub enum ParameterDriftTypeConfig {
5766    /// Linear interpolation
5767    #[default]
5768    Linear,
5769    /// Exponential growth/decay
5770    Exponential,
5771    /// S-curve (logistic)
5772    Logistic,
5773    /// Step function
5774    Step,
5775}
5776
5777/// Statistical validation configuration.
5778#[derive(Debug, Clone, Serialize, Deserialize, Default)]
5779pub struct StatisticalValidationSchemaConfig {
5780    /// Enable statistical validation.
5781    #[serde(default)]
5782    pub enabled: bool,
5783
5784    /// Statistical tests to run.
5785    #[serde(default)]
5786    pub tests: Vec<StatisticalTestConfig>,
5787
5788    /// Validation reporting configuration.
5789    #[serde(default)]
5790    pub reporting: ValidationReportingConfig,
5791}
5792
5793/// Statistical test configuration.
5794#[derive(Debug, Clone, Serialize, Deserialize)]
5795#[serde(tag = "type", rename_all = "snake_case")]
5796pub enum StatisticalTestConfig {
5797    /// Benford's Law first digit test.
5798    BenfordFirstDigit {
5799        /// Threshold MAD for failure.
5800        #[serde(default = "default_benford_threshold")]
5801        threshold_mad: f64,
5802        /// Warning MAD threshold.
5803        #[serde(default = "default_benford_warning")]
5804        warning_mad: f64,
5805    },
5806    /// Distribution fit test.
5807    DistributionFit {
5808        /// Target distribution to test.
5809        target: TargetDistributionConfig,
5810        /// K-S test significance level.
5811        #[serde(default = "default_ks_significance")]
5812        ks_significance: f64,
5813        /// Test method (ks, anderson_darling, chi_squared).
5814        #[serde(default)]
5815        method: DistributionFitMethod,
5816    },
5817    /// Correlation check.
5818    CorrelationCheck {
5819        /// Expected correlations to validate.
5820        expected_correlations: Vec<ExpectedCorrelationConfig>,
5821    },
5822    /// Chi-squared test.
5823    ChiSquared {
5824        /// Number of bins.
5825        #[serde(default = "default_chi_squared_bins")]
5826        bins: usize,
5827        /// Significance level.
5828        #[serde(default = "default_chi_squared_significance")]
5829        significance: f64,
5830    },
5831    /// Anderson-Darling test.
5832    AndersonDarling {
5833        /// Target distribution.
5834        target: TargetDistributionConfig,
5835        /// Significance level.
5836        #[serde(default = "default_ad_significance")]
5837        significance: f64,
5838    },
5839}
5840
5841fn default_benford_threshold() -> f64 {
5842    0.015
5843}
5844
5845fn default_benford_warning() -> f64 {
5846    0.010
5847}
5848
5849fn default_ks_significance() -> f64 {
5850    0.05
5851}
5852
5853fn default_chi_squared_bins() -> usize {
5854    10
5855}
5856
5857fn default_chi_squared_significance() -> f64 {
5858    0.05
5859}
5860
5861fn default_ad_significance() -> f64 {
5862    0.05
5863}
5864
5865/// Target distribution for fit tests.
5866#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
5867#[serde(rename_all = "snake_case")]
5868pub enum TargetDistributionConfig {
5869    /// Normal distribution
5870    Normal,
5871    /// Log-normal distribution
5872    #[default]
5873    LogNormal,
5874    /// Exponential distribution
5875    Exponential,
5876    /// Uniform distribution
5877    Uniform,
5878}
5879
5880/// Distribution fit test method.
5881#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
5882#[serde(rename_all = "snake_case")]
5883pub enum DistributionFitMethod {
5884    /// Kolmogorov-Smirnov test
5885    #[default]
5886    KolmogorovSmirnov,
5887    /// Anderson-Darling test
5888    AndersonDarling,
5889    /// Chi-squared test
5890    ChiSquared,
5891}
5892
5893/// Validation reporting configuration.
5894#[derive(Debug, Clone, Serialize, Deserialize)]
5895pub struct ValidationReportingConfig {
5896    /// Output validation report to file.
5897    #[serde(default)]
5898    pub output_report: bool,
5899
5900    /// Report format.
5901    #[serde(default)]
5902    pub format: ValidationReportFormat,
5903
5904    /// Fail generation if validation fails.
5905    #[serde(default)]
5906    pub fail_on_error: bool,
5907
5908    /// Include detailed statistics in report.
5909    #[serde(default = "default_true")]
5910    pub include_details: bool,
5911}
5912
5913impl Default for ValidationReportingConfig {
5914    fn default() -> Self {
5915        Self {
5916            output_report: false,
5917            format: ValidationReportFormat::Json,
5918            fail_on_error: false,
5919            include_details: true,
5920        }
5921    }
5922}
5923
5924/// Validation report format.
5925#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
5926#[serde(rename_all = "snake_case")]
5927pub enum ValidationReportFormat {
5928    /// JSON format
5929    #[default]
5930    Json,
5931    /// YAML format
5932    Yaml,
5933    /// HTML report
5934    Html,
5935}
5936
5937// =============================================================================
5938// Temporal Patterns Configuration
5939// =============================================================================
5940
5941/// Temporal patterns configuration for business days, period-end dynamics, and processing lags.
5942///
5943/// This section enables sophisticated temporal modeling including:
5944/// - Business day calculations and settlement dates
5945/// - Regional holiday calendars
5946/// - Period-end decay curves (non-flat volume spikes)
5947/// - Processing lag modeling (event-to-posting delays)
5948#[derive(Debug, Clone, Serialize, Deserialize, Default)]
5949pub struct TemporalPatternsConfig {
5950    /// Enable temporal patterns features.
5951    #[serde(default)]
5952    pub enabled: bool,
5953
5954    /// Business day calculation configuration.
5955    #[serde(default)]
5956    pub business_days: BusinessDaySchemaConfig,
5957
5958    /// Regional calendar configuration.
5959    #[serde(default)]
5960    pub calendars: CalendarSchemaConfig,
5961
5962    /// Period-end dynamics configuration.
5963    #[serde(default)]
5964    pub period_end: PeriodEndSchemaConfig,
5965
5966    /// Processing lag configuration.
5967    #[serde(default)]
5968    pub processing_lags: ProcessingLagSchemaConfig,
5969
5970    /// Fiscal calendar configuration (custom year start, 4-4-5, 13-period).
5971    #[serde(default)]
5972    pub fiscal_calendar: FiscalCalendarSchemaConfig,
5973
5974    /// Intra-day patterns configuration (morning spike, lunch dip, EOD rush).
5975    #[serde(default)]
5976    pub intraday: IntraDaySchemaConfig,
5977
5978    /// Timezone handling configuration.
5979    #[serde(default)]
5980    pub timezones: TimezoneSchemaConfig,
5981}
5982
5983/// Business day calculation configuration.
5984#[derive(Debug, Clone, Serialize, Deserialize)]
5985pub struct BusinessDaySchemaConfig {
5986    /// Enable business day calculations.
5987    #[serde(default = "default_true")]
5988    pub enabled: bool,
5989
5990    /// Half-day policy: "full_day", "half_day", "non_business_day".
5991    #[serde(default = "default_half_day_policy")]
5992    pub half_day_policy: String,
5993
5994    /// Settlement rules configuration.
5995    #[serde(default)]
5996    pub settlement_rules: SettlementRulesSchemaConfig,
5997
5998    /// Month-end convention: "modified_following", "preceding", "following", "end_of_month".
5999    #[serde(default = "default_month_end_convention")]
6000    pub month_end_convention: String,
6001
6002    /// Weekend days (e.g., ["saturday", "sunday"] or ["friday", "saturday"] for Middle East).
6003    #[serde(default)]
6004    pub weekend_days: Option<Vec<String>>,
6005}
6006
6007fn default_half_day_policy() -> String {
6008    "half_day".to_string()
6009}
6010
6011fn default_month_end_convention() -> String {
6012    "modified_following".to_string()
6013}
6014
6015impl Default for BusinessDaySchemaConfig {
6016    fn default() -> Self {
6017        Self {
6018            enabled: true,
6019            half_day_policy: "half_day".to_string(),
6020            settlement_rules: SettlementRulesSchemaConfig::default(),
6021            month_end_convention: "modified_following".to_string(),
6022            weekend_days: None,
6023        }
6024    }
6025}
6026
6027/// Settlement rules configuration.
6028#[derive(Debug, Clone, Serialize, Deserialize)]
6029pub struct SettlementRulesSchemaConfig {
6030    /// Equity settlement days (T+N).
6031    #[serde(default = "default_settlement_2")]
6032    pub equity_days: i32,
6033
6034    /// Government bonds settlement days.
6035    #[serde(default = "default_settlement_1")]
6036    pub government_bonds_days: i32,
6037
6038    /// FX spot settlement days.
6039    #[serde(default = "default_settlement_2")]
6040    pub fx_spot_days: i32,
6041
6042    /// Corporate bonds settlement days.
6043    #[serde(default = "default_settlement_2")]
6044    pub corporate_bonds_days: i32,
6045
6046    /// Wire transfer cutoff time (HH:MM format).
6047    #[serde(default = "default_wire_cutoff")]
6048    pub wire_cutoff_time: String,
6049
6050    /// International wire settlement days.
6051    #[serde(default = "default_settlement_1")]
6052    pub wire_international_days: i32,
6053
6054    /// ACH settlement days.
6055    #[serde(default = "default_settlement_1")]
6056    pub ach_days: i32,
6057}
6058
6059fn default_settlement_1() -> i32 {
6060    1
6061}
6062
6063fn default_settlement_2() -> i32 {
6064    2
6065}
6066
6067fn default_wire_cutoff() -> String {
6068    "14:00".to_string()
6069}
6070
6071impl Default for SettlementRulesSchemaConfig {
6072    fn default() -> Self {
6073        Self {
6074            equity_days: 2,
6075            government_bonds_days: 1,
6076            fx_spot_days: 2,
6077            corporate_bonds_days: 2,
6078            wire_cutoff_time: "14:00".to_string(),
6079            wire_international_days: 1,
6080            ach_days: 1,
6081        }
6082    }
6083}
6084
6085/// Regional calendar configuration.
6086#[derive(Debug, Clone, Serialize, Deserialize, Default)]
6087pub struct CalendarSchemaConfig {
6088    /// List of regions to include (e.g., ["US", "DE", "BR", "SG", "KR"]).
6089    #[serde(default)]
6090    pub regions: Vec<String>,
6091
6092    /// Custom holidays (in addition to regional calendars).
6093    #[serde(default)]
6094    pub custom_holidays: Vec<CustomHolidaySchemaConfig>,
6095}
6096
6097/// Custom holiday configuration.
6098#[derive(Debug, Clone, Serialize, Deserialize)]
6099pub struct CustomHolidaySchemaConfig {
6100    /// Holiday name.
6101    pub name: String,
6102    /// Month (1-12).
6103    pub month: u8,
6104    /// Day of month.
6105    pub day: u8,
6106    /// Activity multiplier (0.0-1.0, default 0.05).
6107    #[serde(default = "default_holiday_multiplier")]
6108    pub activity_multiplier: f64,
6109}
6110
6111fn default_holiday_multiplier() -> f64 {
6112    0.05
6113}
6114
6115/// Period-end dynamics configuration.
6116#[derive(Debug, Clone, Serialize, Deserialize, Default)]
6117pub struct PeriodEndSchemaConfig {
6118    /// Model type: "flat", "exponential", "extended_crunch", "daily_profile".
6119    #[serde(default)]
6120    pub model: Option<String>,
6121
6122    /// Month-end configuration.
6123    #[serde(default)]
6124    pub month_end: Option<PeriodEndModelSchemaConfig>,
6125
6126    /// Quarter-end configuration.
6127    #[serde(default)]
6128    pub quarter_end: Option<PeriodEndModelSchemaConfig>,
6129
6130    /// Year-end configuration.
6131    #[serde(default)]
6132    pub year_end: Option<PeriodEndModelSchemaConfig>,
6133}
6134
6135/// Period-end model configuration.
6136#[derive(Debug, Clone, Serialize, Deserialize, Default)]
6137pub struct PeriodEndModelSchemaConfig {
6138    /// Inherit configuration from another period (e.g., "month_end").
6139    #[serde(default)]
6140    pub inherit_from: Option<String>,
6141
6142    /// Additional multiplier on top of inherited/base model.
6143    #[serde(default)]
6144    pub additional_multiplier: Option<f64>,
6145
6146    /// Days before period end to start acceleration (negative, e.g., -10).
6147    #[serde(default)]
6148    pub start_day: Option<i32>,
6149
6150    /// Base multiplier at start of acceleration.
6151    #[serde(default)]
6152    pub base_multiplier: Option<f64>,
6153
6154    /// Peak multiplier on last day.
6155    #[serde(default)]
6156    pub peak_multiplier: Option<f64>,
6157
6158    /// Decay rate for exponential model (0.1-0.5 typical).
6159    #[serde(default)]
6160    pub decay_rate: Option<f64>,
6161
6162    /// Sustained high days for crunch model.
6163    #[serde(default)]
6164    pub sustained_high_days: Option<i32>,
6165}
6166
6167/// Processing lag configuration.
6168#[derive(Debug, Clone, Serialize, Deserialize)]
6169pub struct ProcessingLagSchemaConfig {
6170    /// Enable processing lag calculations.
6171    #[serde(default = "default_true")]
6172    pub enabled: bool,
6173
6174    /// Sales order lag configuration (log-normal mu, sigma).
6175    #[serde(default)]
6176    pub sales_order_lag: Option<LagDistributionSchemaConfig>,
6177
6178    /// Purchase order lag configuration.
6179    #[serde(default)]
6180    pub purchase_order_lag: Option<LagDistributionSchemaConfig>,
6181
6182    /// Goods receipt lag configuration.
6183    #[serde(default)]
6184    pub goods_receipt_lag: Option<LagDistributionSchemaConfig>,
6185
6186    /// Invoice receipt lag configuration.
6187    #[serde(default)]
6188    pub invoice_receipt_lag: Option<LagDistributionSchemaConfig>,
6189
6190    /// Invoice issue lag configuration.
6191    #[serde(default)]
6192    pub invoice_issue_lag: Option<LagDistributionSchemaConfig>,
6193
6194    /// Payment lag configuration.
6195    #[serde(default)]
6196    pub payment_lag: Option<LagDistributionSchemaConfig>,
6197
6198    /// Journal entry lag configuration.
6199    #[serde(default)]
6200    pub journal_entry_lag: Option<LagDistributionSchemaConfig>,
6201
6202    /// Cross-day posting configuration.
6203    #[serde(default)]
6204    pub cross_day_posting: Option<CrossDayPostingSchemaConfig>,
6205}
6206
6207impl Default for ProcessingLagSchemaConfig {
6208    fn default() -> Self {
6209        Self {
6210            enabled: true,
6211            sales_order_lag: None,
6212            purchase_order_lag: None,
6213            goods_receipt_lag: None,
6214            invoice_receipt_lag: None,
6215            invoice_issue_lag: None,
6216            payment_lag: None,
6217            journal_entry_lag: None,
6218            cross_day_posting: None,
6219        }
6220    }
6221}
6222
6223/// Lag distribution configuration (log-normal parameters).
6224#[derive(Debug, Clone, Serialize, Deserialize)]
6225pub struct LagDistributionSchemaConfig {
6226    /// Log-scale mean (mu for log-normal).
6227    pub mu: f64,
6228    /// Log-scale standard deviation (sigma for log-normal).
6229    pub sigma: f64,
6230    /// Minimum lag in hours.
6231    #[serde(default)]
6232    pub min_hours: Option<f64>,
6233    /// Maximum lag in hours.
6234    #[serde(default)]
6235    pub max_hours: Option<f64>,
6236}
6237
6238/// Cross-day posting configuration.
6239#[derive(Debug, Clone, Serialize, Deserialize)]
6240pub struct CrossDayPostingSchemaConfig {
6241    /// Enable cross-day posting logic.
6242    #[serde(default = "default_true")]
6243    pub enabled: bool,
6244
6245    /// Probability of next-day posting by hour (map of hour -> probability).
6246    /// E.g., { 17: 0.7, 19: 0.9, 21: 0.99 }
6247    #[serde(default)]
6248    pub probability_by_hour: std::collections::HashMap<u8, f64>,
6249}
6250
6251impl Default for CrossDayPostingSchemaConfig {
6252    fn default() -> Self {
6253        let mut probability_by_hour = std::collections::HashMap::new();
6254        probability_by_hour.insert(17, 0.3);
6255        probability_by_hour.insert(18, 0.6);
6256        probability_by_hour.insert(19, 0.8);
6257        probability_by_hour.insert(20, 0.9);
6258        probability_by_hour.insert(21, 0.95);
6259        probability_by_hour.insert(22, 0.99);
6260
6261        Self {
6262            enabled: true,
6263            probability_by_hour,
6264        }
6265    }
6266}
6267
6268// =============================================================================
6269// Fiscal Calendar Configuration (P2)
6270// =============================================================================
6271
6272/// Fiscal calendar configuration.
6273///
6274/// Supports calendar year, custom year start, 4-4-5 retail calendar,
6275/// and 13-period calendars.
6276#[derive(Debug, Clone, Serialize, Deserialize, Default)]
6277pub struct FiscalCalendarSchemaConfig {
6278    /// Enable non-standard fiscal calendar.
6279    #[serde(default)]
6280    pub enabled: bool,
6281
6282    /// Fiscal calendar type: "calendar_year", "custom", "four_four_five", "thirteen_period".
6283    #[serde(default = "default_fiscal_calendar_type")]
6284    pub calendar_type: String,
6285
6286    /// Month the fiscal year starts (1-12). Used for custom year start.
6287    #[serde(default)]
6288    pub year_start_month: Option<u8>,
6289
6290    /// Day the fiscal year starts (1-31). Used for custom year start.
6291    #[serde(default)]
6292    pub year_start_day: Option<u8>,
6293
6294    /// 4-4-5 calendar configuration (if calendar_type is "four_four_five").
6295    #[serde(default)]
6296    pub four_four_five: Option<FourFourFiveSchemaConfig>,
6297}
6298
6299fn default_fiscal_calendar_type() -> String {
6300    "calendar_year".to_string()
6301}
6302
6303/// 4-4-5 retail calendar configuration.
6304#[derive(Debug, Clone, Serialize, Deserialize)]
6305pub struct FourFourFiveSchemaConfig {
6306    /// Week pattern: "four_four_five", "four_five_four", "five_four_four".
6307    #[serde(default = "default_week_pattern")]
6308    pub pattern: String,
6309
6310    /// Anchor type: "first_sunday", "last_saturday", "nearest_saturday".
6311    #[serde(default = "default_anchor_type")]
6312    pub anchor_type: String,
6313
6314    /// Anchor month (1-12).
6315    #[serde(default = "default_anchor_month")]
6316    pub anchor_month: u8,
6317
6318    /// Where to place leap week: "q4_period3" or "q1_period1".
6319    #[serde(default = "default_leap_week_placement")]
6320    pub leap_week_placement: String,
6321}
6322
6323fn default_week_pattern() -> String {
6324    "four_four_five".to_string()
6325}
6326
6327fn default_anchor_type() -> String {
6328    "last_saturday".to_string()
6329}
6330
6331fn default_anchor_month() -> u8 {
6332    1 // January
6333}
6334
6335fn default_leap_week_placement() -> String {
6336    "q4_period3".to_string()
6337}
6338
6339impl Default for FourFourFiveSchemaConfig {
6340    fn default() -> Self {
6341        Self {
6342            pattern: "four_four_five".to_string(),
6343            anchor_type: "last_saturday".to_string(),
6344            anchor_month: 1,
6345            leap_week_placement: "q4_period3".to_string(),
6346        }
6347    }
6348}
6349
6350// =============================================================================
6351// Intra-Day Patterns Configuration (P2)
6352// =============================================================================
6353
6354/// Intra-day patterns configuration.
6355///
6356/// Defines time-of-day segments with different activity multipliers
6357/// for realistic modeling of morning spikes, lunch dips, and end-of-day rushes.
6358#[derive(Debug, Clone, Serialize, Deserialize, Default)]
6359pub struct IntraDaySchemaConfig {
6360    /// Enable intra-day patterns.
6361    #[serde(default)]
6362    pub enabled: bool,
6363
6364    /// Custom intra-day segments.
6365    #[serde(default)]
6366    pub segments: Vec<IntraDaySegmentSchemaConfig>,
6367}
6368
6369/// Intra-day segment configuration.
6370#[derive(Debug, Clone, Serialize, Deserialize)]
6371pub struct IntraDaySegmentSchemaConfig {
6372    /// Name of the segment (e.g., "morning_spike", "lunch_dip").
6373    pub name: String,
6374
6375    /// Start time (HH:MM format).
6376    pub start: String,
6377
6378    /// End time (HH:MM format).
6379    pub end: String,
6380
6381    /// Activity multiplier (1.0 = normal).
6382    #[serde(default = "default_multiplier")]
6383    pub multiplier: f64,
6384
6385    /// Posting type: "human", "system", "both".
6386    #[serde(default = "default_posting_type")]
6387    pub posting_type: String,
6388}
6389
6390fn default_multiplier() -> f64 {
6391    1.0
6392}
6393
6394fn default_posting_type() -> String {
6395    "both".to_string()
6396}
6397
6398// =============================================================================
6399// Timezone Configuration
6400// =============================================================================
6401
6402/// Timezone handling configuration for multi-region entities.
6403#[derive(Debug, Clone, Serialize, Deserialize, Default)]
6404pub struct TimezoneSchemaConfig {
6405    /// Enable timezone handling.
6406    #[serde(default)]
6407    pub enabled: bool,
6408
6409    /// Default timezone (IANA format, e.g., "America/New_York").
6410    #[serde(default = "default_timezone")]
6411    pub default_timezone: String,
6412
6413    /// Consolidation timezone for group reporting (IANA format).
6414    #[serde(default = "default_consolidation_timezone")]
6415    pub consolidation_timezone: String,
6416
6417    /// Entity-to-timezone mappings.
6418    /// Supports patterns like "EU_*" -> "Europe/London".
6419    #[serde(default)]
6420    pub entity_mappings: Vec<EntityTimezoneMapping>,
6421}
6422
6423fn default_timezone() -> String {
6424    "America/New_York".to_string()
6425}
6426
6427fn default_consolidation_timezone() -> String {
6428    "UTC".to_string()
6429}
6430
6431/// Mapping from entity pattern to timezone.
6432#[derive(Debug, Clone, Serialize, Deserialize)]
6433pub struct EntityTimezoneMapping {
6434    /// Entity code pattern (e.g., "EU_*", "*_APAC", "1000").
6435    pub pattern: String,
6436
6437    /// Timezone (IANA format, e.g., "Europe/London").
6438    pub timezone: String,
6439}
6440
6441// =============================================================================
6442// Vendor Network Configuration
6443// =============================================================================
6444
6445/// Configuration for multi-tier vendor network generation.
6446#[derive(Debug, Clone, Serialize, Deserialize)]
6447pub struct VendorNetworkSchemaConfig {
6448    /// Enable vendor network generation.
6449    #[serde(default)]
6450    pub enabled: bool,
6451
6452    /// Maximum depth of supply chain tiers (1-3).
6453    #[serde(default = "default_vendor_tier_depth")]
6454    pub depth: u8,
6455
6456    /// Tier 1 vendor count configuration.
6457    #[serde(default)]
6458    pub tier1: TierCountSchemaConfig,
6459
6460    /// Tier 2 vendors per Tier 1 parent.
6461    #[serde(default)]
6462    pub tier2_per_parent: TierCountSchemaConfig,
6463
6464    /// Tier 3 vendors per Tier 2 parent.
6465    #[serde(default)]
6466    pub tier3_per_parent: TierCountSchemaConfig,
6467
6468    /// Vendor cluster distribution.
6469    #[serde(default)]
6470    pub clusters: VendorClusterSchemaConfig,
6471
6472    /// Concentration limits.
6473    #[serde(default)]
6474    pub dependencies: DependencySchemaConfig,
6475}
6476
6477fn default_vendor_tier_depth() -> u8 {
6478    3
6479}
6480
6481impl Default for VendorNetworkSchemaConfig {
6482    fn default() -> Self {
6483        Self {
6484            enabled: false,
6485            depth: 3,
6486            tier1: TierCountSchemaConfig { min: 50, max: 100 },
6487            tier2_per_parent: TierCountSchemaConfig { min: 4, max: 10 },
6488            tier3_per_parent: TierCountSchemaConfig { min: 2, max: 5 },
6489            clusters: VendorClusterSchemaConfig::default(),
6490            dependencies: DependencySchemaConfig::default(),
6491        }
6492    }
6493}
6494
6495/// Tier count configuration.
6496#[derive(Debug, Clone, Serialize, Deserialize)]
6497pub struct TierCountSchemaConfig {
6498    /// Minimum count.
6499    #[serde(default = "default_tier_min")]
6500    pub min: usize,
6501
6502    /// Maximum count.
6503    #[serde(default = "default_tier_max")]
6504    pub max: usize,
6505}
6506
6507fn default_tier_min() -> usize {
6508    5
6509}
6510
6511fn default_tier_max() -> usize {
6512    20
6513}
6514
6515impl Default for TierCountSchemaConfig {
6516    fn default() -> Self {
6517        Self {
6518            min: default_tier_min(),
6519            max: default_tier_max(),
6520        }
6521    }
6522}
6523
6524/// Vendor cluster distribution configuration.
6525#[derive(Debug, Clone, Serialize, Deserialize)]
6526pub struct VendorClusterSchemaConfig {
6527    /// Reliable strategic vendors percentage (default: 0.20).
6528    #[serde(default = "default_reliable_strategic")]
6529    pub reliable_strategic: f64,
6530
6531    /// Standard operational vendors percentage (default: 0.50).
6532    #[serde(default = "default_standard_operational")]
6533    pub standard_operational: f64,
6534
6535    /// Transactional vendors percentage (default: 0.25).
6536    #[serde(default = "default_transactional")]
6537    pub transactional: f64,
6538
6539    /// Problematic vendors percentage (default: 0.05).
6540    #[serde(default = "default_problematic")]
6541    pub problematic: f64,
6542}
6543
6544fn default_reliable_strategic() -> f64 {
6545    0.20
6546}
6547
6548fn default_standard_operational() -> f64 {
6549    0.50
6550}
6551
6552fn default_transactional() -> f64 {
6553    0.25
6554}
6555
6556fn default_problematic() -> f64 {
6557    0.05
6558}
6559
6560impl Default for VendorClusterSchemaConfig {
6561    fn default() -> Self {
6562        Self {
6563            reliable_strategic: 0.20,
6564            standard_operational: 0.50,
6565            transactional: 0.25,
6566            problematic: 0.05,
6567        }
6568    }
6569}
6570
6571/// Dependency and concentration limits configuration.
6572#[derive(Debug, Clone, Serialize, Deserialize)]
6573pub struct DependencySchemaConfig {
6574    /// Maximum concentration for a single vendor (default: 0.15).
6575    #[serde(default = "default_max_single_vendor")]
6576    pub max_single_vendor_concentration: f64,
6577
6578    /// Maximum concentration for top 5 vendors (default: 0.45).
6579    #[serde(default = "default_max_top5")]
6580    pub top_5_concentration: f64,
6581
6582    /// Percentage of single-source vendors (default: 0.05).
6583    #[serde(default = "default_single_source_percent")]
6584    pub single_source_percent: f64,
6585}
6586
6587fn default_max_single_vendor() -> f64 {
6588    0.15
6589}
6590
6591fn default_max_top5() -> f64 {
6592    0.45
6593}
6594
6595fn default_single_source_percent() -> f64 {
6596    0.05
6597}
6598
6599impl Default for DependencySchemaConfig {
6600    fn default() -> Self {
6601        Self {
6602            max_single_vendor_concentration: 0.15,
6603            top_5_concentration: 0.45,
6604            single_source_percent: 0.05,
6605        }
6606    }
6607}
6608
6609// =============================================================================
6610// Customer Segmentation Configuration
6611// =============================================================================
6612
6613/// Configuration for customer segmentation generation.
6614#[derive(Debug, Clone, Default, Serialize, Deserialize)]
6615pub struct CustomerSegmentationSchemaConfig {
6616    /// Enable customer segmentation generation.
6617    #[serde(default)]
6618    pub enabled: bool,
6619
6620    /// Value segment distribution.
6621    #[serde(default)]
6622    pub value_segments: ValueSegmentsSchemaConfig,
6623
6624    /// Lifecycle stage configuration.
6625    #[serde(default)]
6626    pub lifecycle: LifecycleSchemaConfig,
6627
6628    /// Network (referrals, hierarchies) configuration.
6629    #[serde(default)]
6630    pub networks: CustomerNetworksSchemaConfig,
6631}
6632
6633/// Customer value segments distribution configuration.
6634#[derive(Debug, Clone, Serialize, Deserialize)]
6635pub struct ValueSegmentsSchemaConfig {
6636    /// Enterprise segment configuration.
6637    #[serde(default)]
6638    pub enterprise: SegmentDetailSchemaConfig,
6639
6640    /// Mid-market segment configuration.
6641    #[serde(default)]
6642    pub mid_market: SegmentDetailSchemaConfig,
6643
6644    /// SMB segment configuration.
6645    #[serde(default)]
6646    pub smb: SegmentDetailSchemaConfig,
6647
6648    /// Consumer segment configuration.
6649    #[serde(default)]
6650    pub consumer: SegmentDetailSchemaConfig,
6651}
6652
6653impl Default for ValueSegmentsSchemaConfig {
6654    fn default() -> Self {
6655        Self {
6656            enterprise: SegmentDetailSchemaConfig {
6657                revenue_share: 0.40,
6658                customer_share: 0.05,
6659                avg_order_value_range: "50000+".to_string(),
6660            },
6661            mid_market: SegmentDetailSchemaConfig {
6662                revenue_share: 0.35,
6663                customer_share: 0.20,
6664                avg_order_value_range: "5000-50000".to_string(),
6665            },
6666            smb: SegmentDetailSchemaConfig {
6667                revenue_share: 0.20,
6668                customer_share: 0.50,
6669                avg_order_value_range: "500-5000".to_string(),
6670            },
6671            consumer: SegmentDetailSchemaConfig {
6672                revenue_share: 0.05,
6673                customer_share: 0.25,
6674                avg_order_value_range: "50-500".to_string(),
6675            },
6676        }
6677    }
6678}
6679
6680/// Individual segment detail configuration.
6681#[derive(Debug, Clone, Serialize, Deserialize)]
6682pub struct SegmentDetailSchemaConfig {
6683    /// Revenue share for this segment.
6684    #[serde(default)]
6685    pub revenue_share: f64,
6686
6687    /// Customer share for this segment.
6688    #[serde(default)]
6689    pub customer_share: f64,
6690
6691    /// Average order value range (e.g., "5000-50000" or "50000+").
6692    #[serde(default)]
6693    pub avg_order_value_range: String,
6694}
6695
6696impl Default for SegmentDetailSchemaConfig {
6697    fn default() -> Self {
6698        Self {
6699            revenue_share: 0.25,
6700            customer_share: 0.25,
6701            avg_order_value_range: "1000-10000".to_string(),
6702        }
6703    }
6704}
6705
6706/// Customer lifecycle stage configuration.
6707#[derive(Debug, Clone, Serialize, Deserialize)]
6708pub struct LifecycleSchemaConfig {
6709    /// Prospect stage rate.
6710    #[serde(default)]
6711    pub prospect_rate: f64,
6712
6713    /// New customer stage rate.
6714    #[serde(default = "default_new_rate")]
6715    pub new_rate: f64,
6716
6717    /// Growth stage rate.
6718    #[serde(default = "default_growth_rate")]
6719    pub growth_rate: f64,
6720
6721    /// Mature stage rate.
6722    #[serde(default = "default_mature_rate")]
6723    pub mature_rate: f64,
6724
6725    /// At-risk stage rate.
6726    #[serde(default = "default_at_risk_rate")]
6727    pub at_risk_rate: f64,
6728
6729    /// Churned stage rate.
6730    #[serde(default = "default_churned_rate")]
6731    pub churned_rate: f64,
6732}
6733
6734fn default_new_rate() -> f64 {
6735    0.10
6736}
6737
6738fn default_growth_rate() -> f64 {
6739    0.15
6740}
6741
6742fn default_mature_rate() -> f64 {
6743    0.60
6744}
6745
6746fn default_at_risk_rate() -> f64 {
6747    0.10
6748}
6749
6750fn default_churned_rate() -> f64 {
6751    0.05
6752}
6753
6754impl Default for LifecycleSchemaConfig {
6755    fn default() -> Self {
6756        Self {
6757            prospect_rate: 0.0,
6758            new_rate: 0.10,
6759            growth_rate: 0.15,
6760            mature_rate: 0.60,
6761            at_risk_rate: 0.10,
6762            churned_rate: 0.05,
6763        }
6764    }
6765}
6766
6767/// Customer networks configuration (referrals, hierarchies).
6768#[derive(Debug, Clone, Default, Serialize, Deserialize)]
6769pub struct CustomerNetworksSchemaConfig {
6770    /// Referral network configuration.
6771    #[serde(default)]
6772    pub referrals: ReferralSchemaConfig,
6773
6774    /// Corporate hierarchy configuration.
6775    #[serde(default)]
6776    pub corporate_hierarchies: HierarchySchemaConfig,
6777}
6778
6779/// Referral network configuration.
6780#[derive(Debug, Clone, Serialize, Deserialize)]
6781pub struct ReferralSchemaConfig {
6782    /// Enable referral generation.
6783    #[serde(default = "default_true")]
6784    pub enabled: bool,
6785
6786    /// Rate of customers acquired via referral.
6787    #[serde(default = "default_referral_rate")]
6788    pub referral_rate: f64,
6789}
6790
6791fn default_referral_rate() -> f64 {
6792    0.15
6793}
6794
6795impl Default for ReferralSchemaConfig {
6796    fn default() -> Self {
6797        Self {
6798            enabled: true,
6799            referral_rate: 0.15,
6800        }
6801    }
6802}
6803
6804/// Corporate hierarchy configuration.
6805#[derive(Debug, Clone, Serialize, Deserialize)]
6806pub struct HierarchySchemaConfig {
6807    /// Enable corporate hierarchy generation.
6808    #[serde(default = "default_true")]
6809    pub enabled: bool,
6810
6811    /// Rate of customers in hierarchies.
6812    #[serde(default = "default_hierarchy_rate")]
6813    pub probability: f64,
6814}
6815
6816fn default_hierarchy_rate() -> f64 {
6817    0.30
6818}
6819
6820impl Default for HierarchySchemaConfig {
6821    fn default() -> Self {
6822        Self {
6823            enabled: true,
6824            probability: 0.30,
6825        }
6826    }
6827}
6828
6829// =============================================================================
6830// Relationship Strength Configuration
6831// =============================================================================
6832
6833/// Configuration for relationship strength calculation.
6834#[derive(Debug, Clone, Default, Serialize, Deserialize)]
6835pub struct RelationshipStrengthSchemaConfig {
6836    /// Enable relationship strength calculation.
6837    #[serde(default)]
6838    pub enabled: bool,
6839
6840    /// Calculation weights.
6841    #[serde(default)]
6842    pub calculation: StrengthCalculationSchemaConfig,
6843
6844    /// Strength thresholds for classification.
6845    #[serde(default)]
6846    pub thresholds: StrengthThresholdsSchemaConfig,
6847}
6848
6849/// Strength calculation weights configuration.
6850#[derive(Debug, Clone, Serialize, Deserialize)]
6851pub struct StrengthCalculationSchemaConfig {
6852    /// Weight for transaction volume (default: 0.30).
6853    #[serde(default = "default_volume_weight")]
6854    pub transaction_volume_weight: f64,
6855
6856    /// Weight for transaction count (default: 0.25).
6857    #[serde(default = "default_count_weight")]
6858    pub transaction_count_weight: f64,
6859
6860    /// Weight for relationship duration (default: 0.20).
6861    #[serde(default = "default_duration_weight")]
6862    pub relationship_duration_weight: f64,
6863
6864    /// Weight for recency (default: 0.15).
6865    #[serde(default = "default_recency_weight")]
6866    pub recency_weight: f64,
6867
6868    /// Weight for mutual connections (default: 0.10).
6869    #[serde(default = "default_mutual_weight")]
6870    pub mutual_connections_weight: f64,
6871
6872    /// Recency half-life in days (default: 90).
6873    #[serde(default = "default_recency_half_life")]
6874    pub recency_half_life_days: u32,
6875}
6876
6877fn default_volume_weight() -> f64 {
6878    0.30
6879}
6880
6881fn default_count_weight() -> f64 {
6882    0.25
6883}
6884
6885fn default_duration_weight() -> f64 {
6886    0.20
6887}
6888
6889fn default_recency_weight() -> f64 {
6890    0.15
6891}
6892
6893fn default_mutual_weight() -> f64 {
6894    0.10
6895}
6896
6897fn default_recency_half_life() -> u32 {
6898    90
6899}
6900
6901impl Default for StrengthCalculationSchemaConfig {
6902    fn default() -> Self {
6903        Self {
6904            transaction_volume_weight: 0.30,
6905            transaction_count_weight: 0.25,
6906            relationship_duration_weight: 0.20,
6907            recency_weight: 0.15,
6908            mutual_connections_weight: 0.10,
6909            recency_half_life_days: 90,
6910        }
6911    }
6912}
6913
6914/// Strength thresholds for relationship classification.
6915#[derive(Debug, Clone, Serialize, Deserialize)]
6916pub struct StrengthThresholdsSchemaConfig {
6917    /// Threshold for strong relationships (default: 0.7).
6918    #[serde(default = "default_strong_threshold")]
6919    pub strong: f64,
6920
6921    /// Threshold for moderate relationships (default: 0.4).
6922    #[serde(default = "default_moderate_threshold")]
6923    pub moderate: f64,
6924
6925    /// Threshold for weak relationships (default: 0.1).
6926    #[serde(default = "default_weak_threshold")]
6927    pub weak: f64,
6928}
6929
6930fn default_strong_threshold() -> f64 {
6931    0.7
6932}
6933
6934fn default_moderate_threshold() -> f64 {
6935    0.4
6936}
6937
6938fn default_weak_threshold() -> f64 {
6939    0.1
6940}
6941
6942impl Default for StrengthThresholdsSchemaConfig {
6943    fn default() -> Self {
6944        Self {
6945            strong: 0.7,
6946            moderate: 0.4,
6947            weak: 0.1,
6948        }
6949    }
6950}
6951
6952// =============================================================================
6953// Cross-Process Links Configuration
6954// =============================================================================
6955
6956/// Configuration for cross-process linkages.
6957#[derive(Debug, Clone, Serialize, Deserialize)]
6958pub struct CrossProcessLinksSchemaConfig {
6959    /// Enable cross-process link generation.
6960    #[serde(default)]
6961    pub enabled: bool,
6962
6963    /// Enable inventory links between P2P and O2C.
6964    #[serde(default = "default_true")]
6965    pub inventory_p2p_o2c: bool,
6966
6967    /// Enable payment to bank reconciliation links.
6968    #[serde(default = "default_true")]
6969    pub payment_bank_reconciliation: bool,
6970
6971    /// Enable intercompany bilateral matching.
6972    #[serde(default = "default_true")]
6973    pub intercompany_bilateral: bool,
6974
6975    /// Percentage of GR/Deliveries to link via inventory (0.0 - 1.0).
6976    #[serde(default = "default_inventory_link_rate")]
6977    pub inventory_link_rate: f64,
6978}
6979
6980fn default_inventory_link_rate() -> f64 {
6981    0.30
6982}
6983
6984impl Default for CrossProcessLinksSchemaConfig {
6985    fn default() -> Self {
6986        Self {
6987            enabled: false,
6988            inventory_p2p_o2c: true,
6989            payment_bank_reconciliation: true,
6990            intercompany_bilateral: true,
6991            inventory_link_rate: 0.30,
6992        }
6993    }
6994}
6995
6996// =============================================================================
6997// Organizational Events Configuration
6998// =============================================================================
6999
7000/// Configuration for organizational events (acquisitions, divestitures, etc.).
7001#[derive(Debug, Clone, Serialize, Deserialize, Default)]
7002pub struct OrganizationalEventsSchemaConfig {
7003    /// Enable organizational events.
7004    #[serde(default)]
7005    pub enabled: bool,
7006
7007    /// Effect blending mode (multiplicative, additive, maximum, minimum).
7008    #[serde(default)]
7009    pub effect_blending: EffectBlendingModeConfig,
7010
7011    /// Organizational events (acquisitions, divestitures, reorganizations, etc.).
7012    #[serde(default)]
7013    pub events: Vec<OrganizationalEventSchemaConfig>,
7014
7015    /// Process evolution events.
7016    #[serde(default)]
7017    pub process_evolution: Vec<ProcessEvolutionSchemaConfig>,
7018
7019    /// Technology transition events.
7020    #[serde(default)]
7021    pub technology_transitions: Vec<TechnologyTransitionSchemaConfig>,
7022}
7023
7024/// Effect blending mode for combining multiple event effects.
7025#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
7026#[serde(rename_all = "snake_case")]
7027pub enum EffectBlendingModeConfig {
7028    /// Multiply effects together.
7029    #[default]
7030    Multiplicative,
7031    /// Add effects together.
7032    Additive,
7033    /// Take the maximum effect.
7034    Maximum,
7035    /// Take the minimum effect.
7036    Minimum,
7037}
7038
7039/// Configuration for a single organizational event.
7040#[derive(Debug, Clone, Serialize, Deserialize)]
7041pub struct OrganizationalEventSchemaConfig {
7042    /// Event ID.
7043    pub id: String,
7044
7045    /// Event type and configuration.
7046    pub event_type: OrganizationalEventTypeSchemaConfig,
7047
7048    /// Effective date.
7049    pub effective_date: String,
7050
7051    /// Transition duration in months.
7052    #[serde(default = "default_org_transition_months")]
7053    pub transition_months: u32,
7054
7055    /// Description.
7056    #[serde(default)]
7057    pub description: Option<String>,
7058}
7059
7060fn default_org_transition_months() -> u32 {
7061    6
7062}
7063
7064/// Organizational event type configuration.
7065#[derive(Debug, Clone, Serialize, Deserialize)]
7066#[serde(tag = "type", rename_all = "snake_case")]
7067pub enum OrganizationalEventTypeSchemaConfig {
7068    /// Acquisition event.
7069    Acquisition {
7070        /// Acquired entity code.
7071        acquired_entity: String,
7072        /// Volume increase multiplier.
7073        #[serde(default = "default_acquisition_volume")]
7074        volume_increase: f64,
7075        /// Integration error rate.
7076        #[serde(default = "default_acquisition_error")]
7077        integration_error_rate: f64,
7078        /// Parallel posting days.
7079        #[serde(default = "default_parallel_days")]
7080        parallel_posting_days: u32,
7081    },
7082    /// Divestiture event.
7083    Divestiture {
7084        /// Divested entity code.
7085        divested_entity: String,
7086        /// Volume reduction factor.
7087        #[serde(default = "default_divestiture_volume")]
7088        volume_reduction: f64,
7089        /// Remove entity from generation.
7090        #[serde(default = "default_true_val")]
7091        remove_entity: bool,
7092    },
7093    /// Reorganization event.
7094    Reorganization {
7095        /// Cost center remapping.
7096        #[serde(default)]
7097        cost_center_remapping: std::collections::HashMap<String, String>,
7098        /// Transition error rate.
7099        #[serde(default = "default_reorg_error")]
7100        transition_error_rate: f64,
7101    },
7102    /// Leadership change event.
7103    LeadershipChange {
7104        /// Role that changed.
7105        role: String,
7106        /// Policy changes.
7107        #[serde(default)]
7108        policy_changes: Vec<String>,
7109    },
7110    /// Workforce reduction event.
7111    WorkforceReduction {
7112        /// Reduction percentage.
7113        #[serde(default = "default_workforce_reduction")]
7114        reduction_percent: f64,
7115        /// Error rate increase.
7116        #[serde(default = "default_workforce_error")]
7117        error_rate_increase: f64,
7118    },
7119    /// Merger event.
7120    Merger {
7121        /// Merged entity code.
7122        merged_entity: String,
7123        /// Volume increase multiplier.
7124        #[serde(default = "default_merger_volume")]
7125        volume_increase: f64,
7126    },
7127}
7128
7129fn default_acquisition_volume() -> f64 {
7130    1.35
7131}
7132
7133fn default_acquisition_error() -> f64 {
7134    0.05
7135}
7136
7137fn default_parallel_days() -> u32 {
7138    30
7139}
7140
7141fn default_divestiture_volume() -> f64 {
7142    0.70
7143}
7144
7145fn default_true_val() -> bool {
7146    true
7147}
7148
7149fn default_reorg_error() -> f64 {
7150    0.04
7151}
7152
7153fn default_workforce_reduction() -> f64 {
7154    0.10
7155}
7156
7157fn default_workforce_error() -> f64 {
7158    0.05
7159}
7160
7161fn default_merger_volume() -> f64 {
7162    1.80
7163}
7164
7165/// Configuration for a process evolution event.
7166#[derive(Debug, Clone, Serialize, Deserialize)]
7167pub struct ProcessEvolutionSchemaConfig {
7168    /// Event ID.
7169    pub id: String,
7170
7171    /// Event type.
7172    pub event_type: ProcessEvolutionTypeSchemaConfig,
7173
7174    /// Effective date.
7175    pub effective_date: String,
7176
7177    /// Description.
7178    #[serde(default)]
7179    pub description: Option<String>,
7180}
7181
7182/// Process evolution type configuration.
7183#[derive(Debug, Clone, Serialize, Deserialize)]
7184#[serde(tag = "type", rename_all = "snake_case")]
7185pub enum ProcessEvolutionTypeSchemaConfig {
7186    /// Process automation.
7187    ProcessAutomation {
7188        /// Process name.
7189        process_name: String,
7190        /// Manual rate before.
7191        #[serde(default = "default_manual_before")]
7192        manual_rate_before: f64,
7193        /// Manual rate after.
7194        #[serde(default = "default_manual_after")]
7195        manual_rate_after: f64,
7196    },
7197    /// Approval workflow change.
7198    ApprovalWorkflowChange {
7199        /// Description.
7200        description: String,
7201    },
7202    /// Control enhancement.
7203    ControlEnhancement {
7204        /// Control ID.
7205        control_id: String,
7206        /// Error reduction.
7207        #[serde(default = "default_error_reduction")]
7208        error_reduction: f64,
7209    },
7210}
7211
7212fn default_manual_before() -> f64 {
7213    0.80
7214}
7215
7216fn default_manual_after() -> f64 {
7217    0.15
7218}
7219
7220fn default_error_reduction() -> f64 {
7221    0.02
7222}
7223
7224/// Configuration for a technology transition event.
7225#[derive(Debug, Clone, Serialize, Deserialize)]
7226pub struct TechnologyTransitionSchemaConfig {
7227    /// Event ID.
7228    pub id: String,
7229
7230    /// Event type.
7231    pub event_type: TechnologyTransitionTypeSchemaConfig,
7232
7233    /// Description.
7234    #[serde(default)]
7235    pub description: Option<String>,
7236}
7237
7238/// Technology transition type configuration.
7239#[derive(Debug, Clone, Serialize, Deserialize)]
7240#[serde(tag = "type", rename_all = "snake_case")]
7241pub enum TechnologyTransitionTypeSchemaConfig {
7242    /// ERP migration.
7243    ErpMigration {
7244        /// Source system.
7245        source_system: String,
7246        /// Target system.
7247        target_system: String,
7248        /// Cutover date.
7249        cutover_date: String,
7250        /// Stabilization end date.
7251        stabilization_end: String,
7252        /// Duplicate rate during migration.
7253        #[serde(default = "default_erp_duplicate_rate")]
7254        duplicate_rate: f64,
7255        /// Format mismatch rate.
7256        #[serde(default = "default_format_mismatch")]
7257        format_mismatch_rate: f64,
7258    },
7259    /// Module implementation.
7260    ModuleImplementation {
7261        /// Module name.
7262        module_name: String,
7263        /// Go-live date.
7264        go_live_date: String,
7265    },
7266}
7267
7268fn default_erp_duplicate_rate() -> f64 {
7269    0.02
7270}
7271
7272fn default_format_mismatch() -> f64 {
7273    0.03
7274}
7275
7276// =============================================================================
7277// Behavioral Drift Configuration
7278// =============================================================================
7279
7280/// Configuration for behavioral drift (vendor, customer, employee behavior).
7281#[derive(Debug, Clone, Serialize, Deserialize, Default)]
7282pub struct BehavioralDriftSchemaConfig {
7283    /// Enable behavioral drift.
7284    #[serde(default)]
7285    pub enabled: bool,
7286
7287    /// Vendor behavior drift.
7288    #[serde(default)]
7289    pub vendor_behavior: VendorBehaviorSchemaConfig,
7290
7291    /// Customer behavior drift.
7292    #[serde(default)]
7293    pub customer_behavior: CustomerBehaviorSchemaConfig,
7294
7295    /// Employee behavior drift.
7296    #[serde(default)]
7297    pub employee_behavior: EmployeeBehaviorSchemaConfig,
7298
7299    /// Collective behavior drift.
7300    #[serde(default)]
7301    pub collective: CollectiveBehaviorSchemaConfig,
7302}
7303
7304/// Vendor behavior drift configuration.
7305#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7306pub struct VendorBehaviorSchemaConfig {
7307    /// Payment terms drift.
7308    #[serde(default)]
7309    pub payment_terms_drift: PaymentTermsDriftSchemaConfig,
7310
7311    /// Quality drift.
7312    #[serde(default)]
7313    pub quality_drift: QualityDriftSchemaConfig,
7314}
7315
7316/// Payment terms drift configuration.
7317#[derive(Debug, Clone, Serialize, Deserialize)]
7318pub struct PaymentTermsDriftSchemaConfig {
7319    /// Extension rate per year (days).
7320    #[serde(default = "default_extension_rate")]
7321    pub extension_rate_per_year: f64,
7322
7323    /// Economic sensitivity.
7324    #[serde(default = "default_economic_sensitivity")]
7325    pub economic_sensitivity: f64,
7326}
7327
7328fn default_extension_rate() -> f64 {
7329    2.5
7330}
7331
7332fn default_economic_sensitivity() -> f64 {
7333    1.0
7334}
7335
7336impl Default for PaymentTermsDriftSchemaConfig {
7337    fn default() -> Self {
7338        Self {
7339            extension_rate_per_year: 2.5,
7340            economic_sensitivity: 1.0,
7341        }
7342    }
7343}
7344
7345/// Quality drift configuration.
7346#[derive(Debug, Clone, Serialize, Deserialize)]
7347pub struct QualityDriftSchemaConfig {
7348    /// New vendor improvement rate (per year).
7349    #[serde(default = "default_improvement_rate")]
7350    pub new_vendor_improvement_rate: f64,
7351
7352    /// Complacency decline rate (per year after first year).
7353    #[serde(default = "default_decline_rate")]
7354    pub complacency_decline_rate: f64,
7355}
7356
7357fn default_improvement_rate() -> f64 {
7358    0.02
7359}
7360
7361fn default_decline_rate() -> f64 {
7362    0.01
7363}
7364
7365impl Default for QualityDriftSchemaConfig {
7366    fn default() -> Self {
7367        Self {
7368            new_vendor_improvement_rate: 0.02,
7369            complacency_decline_rate: 0.01,
7370        }
7371    }
7372}
7373
7374/// Customer behavior drift configuration.
7375#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7376pub struct CustomerBehaviorSchemaConfig {
7377    /// Payment drift.
7378    #[serde(default)]
7379    pub payment_drift: CustomerPaymentDriftSchemaConfig,
7380
7381    /// Order drift.
7382    #[serde(default)]
7383    pub order_drift: OrderDriftSchemaConfig,
7384}
7385
7386/// Customer payment drift configuration.
7387#[derive(Debug, Clone, Serialize, Deserialize)]
7388pub struct CustomerPaymentDriftSchemaConfig {
7389    /// Days extension during downturn (min, max).
7390    #[serde(default = "default_downturn_extension")]
7391    pub downturn_days_extension: (u32, u32),
7392
7393    /// Bad debt increase during downturn.
7394    #[serde(default = "default_bad_debt_increase")]
7395    pub downturn_bad_debt_increase: f64,
7396}
7397
7398fn default_downturn_extension() -> (u32, u32) {
7399    (5, 15)
7400}
7401
7402fn default_bad_debt_increase() -> f64 {
7403    0.02
7404}
7405
7406impl Default for CustomerPaymentDriftSchemaConfig {
7407    fn default() -> Self {
7408        Self {
7409            downturn_days_extension: (5, 15),
7410            downturn_bad_debt_increase: 0.02,
7411        }
7412    }
7413}
7414
7415/// Order drift configuration.
7416#[derive(Debug, Clone, Serialize, Deserialize)]
7417pub struct OrderDriftSchemaConfig {
7418    /// Digital shift rate (per year).
7419    #[serde(default = "default_digital_shift")]
7420    pub digital_shift_rate: f64,
7421}
7422
7423fn default_digital_shift() -> f64 {
7424    0.05
7425}
7426
7427impl Default for OrderDriftSchemaConfig {
7428    fn default() -> Self {
7429        Self {
7430            digital_shift_rate: 0.05,
7431        }
7432    }
7433}
7434
7435/// Employee behavior drift configuration.
7436#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7437pub struct EmployeeBehaviorSchemaConfig {
7438    /// Approval drift.
7439    #[serde(default)]
7440    pub approval_drift: ApprovalDriftSchemaConfig,
7441
7442    /// Error drift.
7443    #[serde(default)]
7444    pub error_drift: ErrorDriftSchemaConfig,
7445}
7446
7447/// Approval drift configuration.
7448#[derive(Debug, Clone, Serialize, Deserialize)]
7449pub struct ApprovalDriftSchemaConfig {
7450    /// EOM intensity increase per year.
7451    #[serde(default = "default_eom_intensity")]
7452    pub eom_intensity_increase_per_year: f64,
7453
7454    /// Rubber stamp volume threshold.
7455    #[serde(default = "default_rubber_stamp")]
7456    pub rubber_stamp_volume_threshold: u32,
7457}
7458
7459fn default_eom_intensity() -> f64 {
7460    0.05
7461}
7462
7463fn default_rubber_stamp() -> u32 {
7464    50
7465}
7466
7467impl Default for ApprovalDriftSchemaConfig {
7468    fn default() -> Self {
7469        Self {
7470            eom_intensity_increase_per_year: 0.05,
7471            rubber_stamp_volume_threshold: 50,
7472        }
7473    }
7474}
7475
7476/// Error drift configuration.
7477#[derive(Debug, Clone, Serialize, Deserialize)]
7478pub struct ErrorDriftSchemaConfig {
7479    /// New employee error rate.
7480    #[serde(default = "default_new_error")]
7481    pub new_employee_error_rate: f64,
7482
7483    /// Learning curve months.
7484    #[serde(default = "default_learning_months")]
7485    pub learning_curve_months: u32,
7486}
7487
7488fn default_new_error() -> f64 {
7489    0.08
7490}
7491
7492fn default_learning_months() -> u32 {
7493    6
7494}
7495
7496impl Default for ErrorDriftSchemaConfig {
7497    fn default() -> Self {
7498        Self {
7499            new_employee_error_rate: 0.08,
7500            learning_curve_months: 6,
7501        }
7502    }
7503}
7504
7505/// Collective behavior drift configuration.
7506#[derive(Debug, Clone, Serialize, Deserialize, Default)]
7507pub struct CollectiveBehaviorSchemaConfig {
7508    /// Automation adoption configuration.
7509    #[serde(default)]
7510    pub automation_adoption: AutomationAdoptionSchemaConfig,
7511}
7512
7513/// Automation adoption configuration.
7514#[derive(Debug, Clone, Serialize, Deserialize)]
7515pub struct AutomationAdoptionSchemaConfig {
7516    /// Enable S-curve adoption model.
7517    #[serde(default)]
7518    pub s_curve_enabled: bool,
7519
7520    /// Adoption midpoint in months.
7521    #[serde(default = "default_midpoint")]
7522    pub adoption_midpoint_months: u32,
7523
7524    /// Steepness of adoption curve.
7525    #[serde(default = "default_steepness")]
7526    pub steepness: f64,
7527}
7528
7529fn default_midpoint() -> u32 {
7530    24
7531}
7532
7533fn default_steepness() -> f64 {
7534    0.15
7535}
7536
7537impl Default for AutomationAdoptionSchemaConfig {
7538    fn default() -> Self {
7539        Self {
7540            s_curve_enabled: false,
7541            adoption_midpoint_months: 24,
7542            steepness: 0.15,
7543        }
7544    }
7545}
7546
7547// =============================================================================
7548// Market Drift Configuration
7549// =============================================================================
7550
7551/// Configuration for market drift (economic cycles, commodities, price shocks).
7552#[derive(Debug, Clone, Serialize, Deserialize, Default)]
7553pub struct MarketDriftSchemaConfig {
7554    /// Enable market drift.
7555    #[serde(default)]
7556    pub enabled: bool,
7557
7558    /// Economic cycle configuration.
7559    #[serde(default)]
7560    pub economic_cycle: MarketEconomicCycleSchemaConfig,
7561
7562    /// Industry-specific cycles.
7563    #[serde(default)]
7564    pub industry_cycles: std::collections::HashMap<String, IndustryCycleSchemaConfig>,
7565
7566    /// Commodity drift configuration.
7567    #[serde(default)]
7568    pub commodities: CommoditiesSchemaConfig,
7569}
7570
7571/// Market economic cycle configuration.
7572#[derive(Debug, Clone, Serialize, Deserialize)]
7573pub struct MarketEconomicCycleSchemaConfig {
7574    /// Enable economic cycle.
7575    #[serde(default)]
7576    pub enabled: bool,
7577
7578    /// Cycle type.
7579    #[serde(default)]
7580    pub cycle_type: CycleTypeSchemaConfig,
7581
7582    /// Cycle period in months.
7583    #[serde(default = "default_market_cycle_period")]
7584    pub period_months: u32,
7585
7586    /// Amplitude.
7587    #[serde(default = "default_market_amplitude")]
7588    pub amplitude: f64,
7589
7590    /// Recession configuration.
7591    #[serde(default)]
7592    pub recession: RecessionSchemaConfig,
7593}
7594
7595fn default_market_cycle_period() -> u32 {
7596    48
7597}
7598
7599fn default_market_amplitude() -> f64 {
7600    0.15
7601}
7602
7603impl Default for MarketEconomicCycleSchemaConfig {
7604    fn default() -> Self {
7605        Self {
7606            enabled: false,
7607            cycle_type: CycleTypeSchemaConfig::Sinusoidal,
7608            period_months: 48,
7609            amplitude: 0.15,
7610            recession: RecessionSchemaConfig::default(),
7611        }
7612    }
7613}
7614
7615/// Cycle type configuration.
7616#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
7617#[serde(rename_all = "snake_case")]
7618pub enum CycleTypeSchemaConfig {
7619    /// Sinusoidal cycle.
7620    #[default]
7621    Sinusoidal,
7622    /// Asymmetric cycle.
7623    Asymmetric,
7624    /// Mean-reverting cycle.
7625    MeanReverting,
7626}
7627
7628/// Recession configuration.
7629#[derive(Debug, Clone, Serialize, Deserialize)]
7630pub struct RecessionSchemaConfig {
7631    /// Enable recession simulation.
7632    #[serde(default)]
7633    pub enabled: bool,
7634
7635    /// Probability per year.
7636    #[serde(default = "default_recession_prob")]
7637    pub probability_per_year: f64,
7638
7639    /// Severity.
7640    #[serde(default)]
7641    pub severity: RecessionSeveritySchemaConfig,
7642
7643    /// Specific recession periods.
7644    #[serde(default)]
7645    pub recession_periods: Vec<RecessionPeriodSchemaConfig>,
7646}
7647
7648fn default_recession_prob() -> f64 {
7649    0.10
7650}
7651
7652impl Default for RecessionSchemaConfig {
7653    fn default() -> Self {
7654        Self {
7655            enabled: false,
7656            probability_per_year: 0.10,
7657            severity: RecessionSeveritySchemaConfig::Moderate,
7658            recession_periods: Vec::new(),
7659        }
7660    }
7661}
7662
7663/// Recession severity configuration.
7664#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
7665#[serde(rename_all = "snake_case")]
7666pub enum RecessionSeveritySchemaConfig {
7667    /// Mild recession.
7668    Mild,
7669    /// Moderate recession.
7670    #[default]
7671    Moderate,
7672    /// Severe recession.
7673    Severe,
7674}
7675
7676/// Recession period configuration.
7677#[derive(Debug, Clone, Serialize, Deserialize)]
7678pub struct RecessionPeriodSchemaConfig {
7679    /// Start month.
7680    pub start_month: u32,
7681    /// Duration in months.
7682    pub duration_months: u32,
7683}
7684
7685/// Industry cycle configuration.
7686#[derive(Debug, Clone, Serialize, Deserialize)]
7687pub struct IndustryCycleSchemaConfig {
7688    /// Period in months.
7689    #[serde(default = "default_industry_period")]
7690    pub period_months: u32,
7691
7692    /// Amplitude.
7693    #[serde(default = "default_industry_amp")]
7694    pub amplitude: f64,
7695}
7696
7697fn default_industry_period() -> u32 {
7698    36
7699}
7700
7701fn default_industry_amp() -> f64 {
7702    0.20
7703}
7704
7705/// Commodities drift configuration.
7706#[derive(Debug, Clone, Serialize, Deserialize, Default)]
7707pub struct CommoditiesSchemaConfig {
7708    /// Enable commodity drift.
7709    #[serde(default)]
7710    pub enabled: bool,
7711
7712    /// Commodity items.
7713    #[serde(default)]
7714    pub items: Vec<CommodityItemSchemaConfig>,
7715}
7716
7717/// Commodity item configuration.
7718#[derive(Debug, Clone, Serialize, Deserialize)]
7719pub struct CommodityItemSchemaConfig {
7720    /// Commodity name.
7721    pub name: String,
7722
7723    /// Volatility.
7724    #[serde(default = "default_volatility")]
7725    pub volatility: f64,
7726
7727    /// COGS pass-through.
7728    #[serde(default)]
7729    pub cogs_pass_through: f64,
7730
7731    /// Overhead pass-through.
7732    #[serde(default)]
7733    pub overhead_pass_through: f64,
7734}
7735
7736fn default_volatility() -> f64 {
7737    0.20
7738}
7739
7740// =============================================================================
7741// Drift Labeling Configuration
7742// =============================================================================
7743
7744/// Configuration for drift ground truth labeling.
7745#[derive(Debug, Clone, Serialize, Deserialize, Default)]
7746pub struct DriftLabelingSchemaConfig {
7747    /// Enable drift labeling.
7748    #[serde(default)]
7749    pub enabled: bool,
7750
7751    /// Statistical drift labeling.
7752    #[serde(default)]
7753    pub statistical: StatisticalDriftLabelingSchemaConfig,
7754
7755    /// Categorical drift labeling.
7756    #[serde(default)]
7757    pub categorical: CategoricalDriftLabelingSchemaConfig,
7758
7759    /// Temporal drift labeling.
7760    #[serde(default)]
7761    pub temporal: TemporalDriftLabelingSchemaConfig,
7762
7763    /// Regulatory calendar preset.
7764    #[serde(default)]
7765    pub regulatory_calendar_preset: Option<String>,
7766}
7767
7768/// Statistical drift labeling configuration.
7769#[derive(Debug, Clone, Serialize, Deserialize)]
7770pub struct StatisticalDriftLabelingSchemaConfig {
7771    /// Enable statistical drift labeling.
7772    #[serde(default = "default_true_val")]
7773    pub enabled: bool,
7774
7775    /// Minimum magnitude threshold.
7776    #[serde(default = "default_min_magnitude")]
7777    pub min_magnitude_threshold: f64,
7778}
7779
7780fn default_min_magnitude() -> f64 {
7781    0.05
7782}
7783
7784impl Default for StatisticalDriftLabelingSchemaConfig {
7785    fn default() -> Self {
7786        Self {
7787            enabled: true,
7788            min_magnitude_threshold: 0.05,
7789        }
7790    }
7791}
7792
7793/// Categorical drift labeling configuration.
7794#[derive(Debug, Clone, Serialize, Deserialize)]
7795pub struct CategoricalDriftLabelingSchemaConfig {
7796    /// Enable categorical drift labeling.
7797    #[serde(default = "default_true_val")]
7798    pub enabled: bool,
7799}
7800
7801impl Default for CategoricalDriftLabelingSchemaConfig {
7802    fn default() -> Self {
7803        Self { enabled: true }
7804    }
7805}
7806
7807/// Temporal drift labeling configuration.
7808#[derive(Debug, Clone, Serialize, Deserialize)]
7809pub struct TemporalDriftLabelingSchemaConfig {
7810    /// Enable temporal drift labeling.
7811    #[serde(default = "default_true_val")]
7812    pub enabled: bool,
7813}
7814
7815impl Default for TemporalDriftLabelingSchemaConfig {
7816    fn default() -> Self {
7817        Self { enabled: true }
7818    }
7819}
7820
7821// =============================================================================
7822// Enhanced Anomaly Injection Configuration
7823// =============================================================================
7824
7825/// Enhanced anomaly injection configuration.
7826///
7827/// Provides comprehensive anomaly injection capabilities including:
7828/// - Multi-stage fraud schemes (embezzlement, revenue manipulation, kickbacks)
7829/// - Correlated anomaly injection (co-occurrence patterns, error cascades)
7830/// - Near-miss generation for false positive reduction
7831/// - Detection difficulty classification
7832/// - Context-aware injection based on entity behavior
7833#[derive(Debug, Clone, Serialize, Deserialize, Default)]
7834pub struct EnhancedAnomalyConfig {
7835    /// Enable enhanced anomaly injection.
7836    #[serde(default)]
7837    pub enabled: bool,
7838
7839    /// Base anomaly rates.
7840    #[serde(default)]
7841    pub rates: AnomalyRateConfig,
7842
7843    /// Multi-stage fraud scheme configuration.
7844    #[serde(default)]
7845    pub multi_stage_schemes: MultiStageSchemeConfig,
7846
7847    /// Correlated anomaly injection configuration.
7848    #[serde(default)]
7849    pub correlated_injection: CorrelatedInjectionConfig,
7850
7851    /// Near-miss generation configuration.
7852    #[serde(default)]
7853    pub near_miss: NearMissConfig,
7854
7855    /// Detection difficulty classification configuration.
7856    #[serde(default)]
7857    pub difficulty_classification: DifficultyClassificationConfig,
7858
7859    /// Context-aware injection configuration.
7860    #[serde(default)]
7861    pub context_aware: ContextAwareConfig,
7862
7863    /// Enhanced labeling configuration.
7864    #[serde(default)]
7865    pub labeling: EnhancedLabelingConfig,
7866}
7867
7868/// Base anomaly rate configuration.
7869#[derive(Debug, Clone, Serialize, Deserialize)]
7870pub struct AnomalyRateConfig {
7871    /// Total anomaly rate (0.0 to 1.0).
7872    #[serde(default = "default_total_anomaly_rate")]
7873    pub total_rate: f64,
7874
7875    /// Fraud anomaly rate.
7876    #[serde(default = "default_fraud_anomaly_rate")]
7877    pub fraud_rate: f64,
7878
7879    /// Error anomaly rate.
7880    #[serde(default = "default_error_anomaly_rate")]
7881    pub error_rate: f64,
7882
7883    /// Process issue rate.
7884    #[serde(default = "default_process_anomaly_rate")]
7885    pub process_rate: f64,
7886}
7887
7888fn default_total_anomaly_rate() -> f64 {
7889    0.03
7890}
7891fn default_fraud_anomaly_rate() -> f64 {
7892    0.01
7893}
7894fn default_error_anomaly_rate() -> f64 {
7895    0.015
7896}
7897fn default_process_anomaly_rate() -> f64 {
7898    0.005
7899}
7900
7901impl Default for AnomalyRateConfig {
7902    fn default() -> Self {
7903        Self {
7904            total_rate: default_total_anomaly_rate(),
7905            fraud_rate: default_fraud_anomaly_rate(),
7906            error_rate: default_error_anomaly_rate(),
7907            process_rate: default_process_anomaly_rate(),
7908        }
7909    }
7910}
7911
7912/// Multi-stage fraud scheme configuration.
7913#[derive(Debug, Clone, Serialize, Deserialize, Default)]
7914pub struct MultiStageSchemeConfig {
7915    /// Enable multi-stage fraud schemes.
7916    #[serde(default)]
7917    pub enabled: bool,
7918
7919    /// Embezzlement scheme configuration.
7920    #[serde(default)]
7921    pub embezzlement: EmbezzlementSchemeConfig,
7922
7923    /// Revenue manipulation scheme configuration.
7924    #[serde(default)]
7925    pub revenue_manipulation: RevenueManipulationSchemeConfig,
7926
7927    /// Vendor kickback scheme configuration.
7928    #[serde(default)]
7929    pub kickback: KickbackSchemeConfig,
7930}
7931
7932/// Embezzlement scheme configuration.
7933#[derive(Debug, Clone, Serialize, Deserialize)]
7934pub struct EmbezzlementSchemeConfig {
7935    /// Probability of starting an embezzlement scheme per perpetrator per year.
7936    #[serde(default = "default_embezzlement_probability")]
7937    pub probability: f64,
7938
7939    /// Testing stage configuration.
7940    #[serde(default)]
7941    pub testing_stage: SchemeStageConfig,
7942
7943    /// Escalation stage configuration.
7944    #[serde(default)]
7945    pub escalation_stage: SchemeStageConfig,
7946
7947    /// Acceleration stage configuration.
7948    #[serde(default)]
7949    pub acceleration_stage: SchemeStageConfig,
7950
7951    /// Desperation stage configuration.
7952    #[serde(default)]
7953    pub desperation_stage: SchemeStageConfig,
7954}
7955
7956fn default_embezzlement_probability() -> f64 {
7957    0.02
7958}
7959
7960impl Default for EmbezzlementSchemeConfig {
7961    fn default() -> Self {
7962        Self {
7963            probability: default_embezzlement_probability(),
7964            testing_stage: SchemeStageConfig {
7965                duration_months: 2,
7966                amount_min: 100.0,
7967                amount_max: 500.0,
7968                transaction_count_min: 2,
7969                transaction_count_max: 5,
7970                difficulty: "hard".to_string(),
7971            },
7972            escalation_stage: SchemeStageConfig {
7973                duration_months: 6,
7974                amount_min: 500.0,
7975                amount_max: 2000.0,
7976                transaction_count_min: 3,
7977                transaction_count_max: 8,
7978                difficulty: "moderate".to_string(),
7979            },
7980            acceleration_stage: SchemeStageConfig {
7981                duration_months: 3,
7982                amount_min: 2000.0,
7983                amount_max: 10000.0,
7984                transaction_count_min: 5,
7985                transaction_count_max: 12,
7986                difficulty: "easy".to_string(),
7987            },
7988            desperation_stage: SchemeStageConfig {
7989                duration_months: 1,
7990                amount_min: 10000.0,
7991                amount_max: 50000.0,
7992                transaction_count_min: 3,
7993                transaction_count_max: 6,
7994                difficulty: "trivial".to_string(),
7995            },
7996        }
7997    }
7998}
7999
8000/// Revenue manipulation scheme configuration.
8001#[derive(Debug, Clone, Serialize, Deserialize)]
8002pub struct RevenueManipulationSchemeConfig {
8003    /// Probability of starting a revenue manipulation scheme per period.
8004    #[serde(default = "default_revenue_manipulation_probability")]
8005    pub probability: f64,
8006
8007    /// Early revenue recognition inflation target (Q4).
8008    #[serde(default = "default_early_recognition_target")]
8009    pub early_recognition_target: f64,
8010
8011    /// Expense deferral inflation target (Q1).
8012    #[serde(default = "default_expense_deferral_target")]
8013    pub expense_deferral_target: f64,
8014
8015    /// Reserve release inflation target (Q2).
8016    #[serde(default = "default_reserve_release_target")]
8017    pub reserve_release_target: f64,
8018
8019    /// Channel stuffing inflation target (Q4).
8020    #[serde(default = "default_channel_stuffing_target")]
8021    pub channel_stuffing_target: f64,
8022}
8023
8024fn default_revenue_manipulation_probability() -> f64 {
8025    0.01
8026}
8027fn default_early_recognition_target() -> f64 {
8028    0.02
8029}
8030fn default_expense_deferral_target() -> f64 {
8031    0.03
8032}
8033fn default_reserve_release_target() -> f64 {
8034    0.02
8035}
8036fn default_channel_stuffing_target() -> f64 {
8037    0.05
8038}
8039
8040impl Default for RevenueManipulationSchemeConfig {
8041    fn default() -> Self {
8042        Self {
8043            probability: default_revenue_manipulation_probability(),
8044            early_recognition_target: default_early_recognition_target(),
8045            expense_deferral_target: default_expense_deferral_target(),
8046            reserve_release_target: default_reserve_release_target(),
8047            channel_stuffing_target: default_channel_stuffing_target(),
8048        }
8049    }
8050}
8051
8052/// Vendor kickback scheme configuration.
8053#[derive(Debug, Clone, Serialize, Deserialize)]
8054pub struct KickbackSchemeConfig {
8055    /// Probability of starting a kickback scheme.
8056    #[serde(default = "default_kickback_probability")]
8057    pub probability: f64,
8058
8059    /// Minimum price inflation percentage.
8060    #[serde(default = "default_kickback_inflation_min")]
8061    pub inflation_min: f64,
8062
8063    /// Maximum price inflation percentage.
8064    #[serde(default = "default_kickback_inflation_max")]
8065    pub inflation_max: f64,
8066
8067    /// Kickback percentage (of inflation).
8068    #[serde(default = "default_kickback_percent")]
8069    pub kickback_percent: f64,
8070
8071    /// Setup duration in months.
8072    #[serde(default = "default_kickback_setup_months")]
8073    pub setup_months: u32,
8074
8075    /// Main operation duration in months.
8076    #[serde(default = "default_kickback_operation_months")]
8077    pub operation_months: u32,
8078}
8079
8080fn default_kickback_probability() -> f64 {
8081    0.01
8082}
8083fn default_kickback_inflation_min() -> f64 {
8084    0.10
8085}
8086fn default_kickback_inflation_max() -> f64 {
8087    0.25
8088}
8089fn default_kickback_percent() -> f64 {
8090    0.50
8091}
8092fn default_kickback_setup_months() -> u32 {
8093    3
8094}
8095fn default_kickback_operation_months() -> u32 {
8096    12
8097}
8098
8099impl Default for KickbackSchemeConfig {
8100    fn default() -> Self {
8101        Self {
8102            probability: default_kickback_probability(),
8103            inflation_min: default_kickback_inflation_min(),
8104            inflation_max: default_kickback_inflation_max(),
8105            kickback_percent: default_kickback_percent(),
8106            setup_months: default_kickback_setup_months(),
8107            operation_months: default_kickback_operation_months(),
8108        }
8109    }
8110}
8111
8112/// Individual scheme stage configuration.
8113#[derive(Debug, Clone, Serialize, Deserialize)]
8114pub struct SchemeStageConfig {
8115    /// Duration in months.
8116    pub duration_months: u32,
8117
8118    /// Minimum transaction amount.
8119    pub amount_min: f64,
8120
8121    /// Maximum transaction amount.
8122    pub amount_max: f64,
8123
8124    /// Minimum number of transactions.
8125    pub transaction_count_min: u32,
8126
8127    /// Maximum number of transactions.
8128    pub transaction_count_max: u32,
8129
8130    /// Detection difficulty level (trivial, easy, moderate, hard, expert).
8131    pub difficulty: String,
8132}
8133
8134impl Default for SchemeStageConfig {
8135    fn default() -> Self {
8136        Self {
8137            duration_months: 3,
8138            amount_min: 100.0,
8139            amount_max: 1000.0,
8140            transaction_count_min: 2,
8141            transaction_count_max: 10,
8142            difficulty: "moderate".to_string(),
8143        }
8144    }
8145}
8146
8147/// Correlated anomaly injection configuration.
8148#[derive(Debug, Clone, Serialize, Deserialize)]
8149pub struct CorrelatedInjectionConfig {
8150    /// Enable correlated anomaly injection.
8151    #[serde(default)]
8152    pub enabled: bool,
8153
8154    /// Enable fraud concealment co-occurrence patterns.
8155    #[serde(default = "default_true_val")]
8156    pub fraud_concealment: bool,
8157
8158    /// Enable error cascade patterns.
8159    #[serde(default = "default_true_val")]
8160    pub error_cascade: bool,
8161
8162    /// Enable temporal clustering (period-end spikes).
8163    #[serde(default = "default_true_val")]
8164    pub temporal_clustering: bool,
8165
8166    /// Temporal clustering configuration.
8167    #[serde(default)]
8168    pub temporal_clustering_config: TemporalClusteringConfig,
8169
8170    /// Co-occurrence patterns.
8171    #[serde(default)]
8172    pub co_occurrence_patterns: Vec<CoOccurrencePatternConfig>,
8173}
8174
8175impl Default for CorrelatedInjectionConfig {
8176    fn default() -> Self {
8177        Self {
8178            enabled: false,
8179            fraud_concealment: true,
8180            error_cascade: true,
8181            temporal_clustering: true,
8182            temporal_clustering_config: TemporalClusteringConfig::default(),
8183            co_occurrence_patterns: Vec::new(),
8184        }
8185    }
8186}
8187
8188/// Temporal clustering configuration.
8189#[derive(Debug, Clone, Serialize, Deserialize)]
8190pub struct TemporalClusteringConfig {
8191    /// Period-end error multiplier.
8192    #[serde(default = "default_period_end_multiplier")]
8193    pub period_end_multiplier: f64,
8194
8195    /// Number of business days before period end to apply multiplier.
8196    #[serde(default = "default_period_end_days")]
8197    pub period_end_days: u32,
8198
8199    /// Quarter-end additional multiplier.
8200    #[serde(default = "default_quarter_end_multiplier")]
8201    pub quarter_end_multiplier: f64,
8202
8203    /// Year-end additional multiplier.
8204    #[serde(default = "default_year_end_multiplier")]
8205    pub year_end_multiplier: f64,
8206}
8207
8208fn default_period_end_multiplier() -> f64 {
8209    2.5
8210}
8211fn default_period_end_days() -> u32 {
8212    5
8213}
8214fn default_quarter_end_multiplier() -> f64 {
8215    1.5
8216}
8217fn default_year_end_multiplier() -> f64 {
8218    2.0
8219}
8220
8221impl Default for TemporalClusteringConfig {
8222    fn default() -> Self {
8223        Self {
8224            period_end_multiplier: default_period_end_multiplier(),
8225            period_end_days: default_period_end_days(),
8226            quarter_end_multiplier: default_quarter_end_multiplier(),
8227            year_end_multiplier: default_year_end_multiplier(),
8228        }
8229    }
8230}
8231
8232/// Co-occurrence pattern configuration.
8233#[derive(Debug, Clone, Serialize, Deserialize)]
8234pub struct CoOccurrencePatternConfig {
8235    /// Pattern name.
8236    pub name: String,
8237
8238    /// Primary anomaly type that triggers the pattern.
8239    pub primary_type: String,
8240
8241    /// Correlated anomalies.
8242    pub correlated: Vec<CorrelatedAnomalyConfig>,
8243}
8244
8245/// Correlated anomaly configuration.
8246#[derive(Debug, Clone, Serialize, Deserialize)]
8247pub struct CorrelatedAnomalyConfig {
8248    /// Anomaly type.
8249    pub anomaly_type: String,
8250
8251    /// Probability of occurrence (0.0 to 1.0).
8252    pub probability: f64,
8253
8254    /// Minimum lag in days.
8255    pub lag_days_min: i32,
8256
8257    /// Maximum lag in days.
8258    pub lag_days_max: i32,
8259}
8260
8261/// Near-miss generation configuration.
8262#[derive(Debug, Clone, Serialize, Deserialize)]
8263pub struct NearMissConfig {
8264    /// Enable near-miss generation.
8265    #[serde(default)]
8266    pub enabled: bool,
8267
8268    /// Proportion of "anomalies" that are actually near-misses (0.0 to 1.0).
8269    #[serde(default = "default_near_miss_proportion")]
8270    pub proportion: f64,
8271
8272    /// Enable near-duplicate pattern.
8273    #[serde(default = "default_true_val")]
8274    pub near_duplicate: bool,
8275
8276    /// Near-duplicate date difference range in days.
8277    #[serde(default)]
8278    pub near_duplicate_days: NearDuplicateDaysConfig,
8279
8280    /// Enable threshold proximity pattern.
8281    #[serde(default = "default_true_val")]
8282    pub threshold_proximity: bool,
8283
8284    /// Threshold proximity range (e.g., 0.90-0.99 of threshold).
8285    #[serde(default)]
8286    pub threshold_proximity_range: ThresholdProximityRangeConfig,
8287
8288    /// Enable unusual but legitimate patterns.
8289    #[serde(default = "default_true_val")]
8290    pub unusual_legitimate: bool,
8291
8292    /// Types of unusual legitimate patterns to generate.
8293    #[serde(default = "default_unusual_legitimate_types")]
8294    pub unusual_legitimate_types: Vec<String>,
8295
8296    /// Enable corrected error patterns.
8297    #[serde(default = "default_true_val")]
8298    pub corrected_errors: bool,
8299
8300    /// Corrected error correction lag range in days.
8301    #[serde(default)]
8302    pub corrected_error_lag: CorrectedErrorLagConfig,
8303}
8304
8305fn default_near_miss_proportion() -> f64 {
8306    0.30
8307}
8308
8309fn default_unusual_legitimate_types() -> Vec<String> {
8310    vec![
8311        "year_end_bonus".to_string(),
8312        "contract_prepayment".to_string(),
8313        "insurance_claim".to_string(),
8314        "settlement_payment".to_string(),
8315    ]
8316}
8317
8318impl Default for NearMissConfig {
8319    fn default() -> Self {
8320        Self {
8321            enabled: false,
8322            proportion: default_near_miss_proportion(),
8323            near_duplicate: true,
8324            near_duplicate_days: NearDuplicateDaysConfig::default(),
8325            threshold_proximity: true,
8326            threshold_proximity_range: ThresholdProximityRangeConfig::default(),
8327            unusual_legitimate: true,
8328            unusual_legitimate_types: default_unusual_legitimate_types(),
8329            corrected_errors: true,
8330            corrected_error_lag: CorrectedErrorLagConfig::default(),
8331        }
8332    }
8333}
8334
8335/// Near-duplicate days configuration.
8336#[derive(Debug, Clone, Serialize, Deserialize)]
8337pub struct NearDuplicateDaysConfig {
8338    /// Minimum days apart.
8339    #[serde(default = "default_near_duplicate_min")]
8340    pub min: u32,
8341
8342    /// Maximum days apart.
8343    #[serde(default = "default_near_duplicate_max")]
8344    pub max: u32,
8345}
8346
8347fn default_near_duplicate_min() -> u32 {
8348    1
8349}
8350fn default_near_duplicate_max() -> u32 {
8351    3
8352}
8353
8354impl Default for NearDuplicateDaysConfig {
8355    fn default() -> Self {
8356        Self {
8357            min: default_near_duplicate_min(),
8358            max: default_near_duplicate_max(),
8359        }
8360    }
8361}
8362
8363/// Threshold proximity range configuration.
8364#[derive(Debug, Clone, Serialize, Deserialize)]
8365pub struct ThresholdProximityRangeConfig {
8366    /// Minimum proximity (e.g., 0.90 = 90% of threshold).
8367    #[serde(default = "default_threshold_proximity_min")]
8368    pub min: f64,
8369
8370    /// Maximum proximity (e.g., 0.99 = 99% of threshold).
8371    #[serde(default = "default_threshold_proximity_max")]
8372    pub max: f64,
8373}
8374
8375fn default_threshold_proximity_min() -> f64 {
8376    0.90
8377}
8378fn default_threshold_proximity_max() -> f64 {
8379    0.99
8380}
8381
8382impl Default for ThresholdProximityRangeConfig {
8383    fn default() -> Self {
8384        Self {
8385            min: default_threshold_proximity_min(),
8386            max: default_threshold_proximity_max(),
8387        }
8388    }
8389}
8390
8391/// Corrected error lag configuration.
8392#[derive(Debug, Clone, Serialize, Deserialize)]
8393pub struct CorrectedErrorLagConfig {
8394    /// Minimum correction lag in days.
8395    #[serde(default = "default_corrected_error_lag_min")]
8396    pub min: u32,
8397
8398    /// Maximum correction lag in days.
8399    #[serde(default = "default_corrected_error_lag_max")]
8400    pub max: u32,
8401}
8402
8403fn default_corrected_error_lag_min() -> u32 {
8404    1
8405}
8406fn default_corrected_error_lag_max() -> u32 {
8407    5
8408}
8409
8410impl Default for CorrectedErrorLagConfig {
8411    fn default() -> Self {
8412        Self {
8413            min: default_corrected_error_lag_min(),
8414            max: default_corrected_error_lag_max(),
8415        }
8416    }
8417}
8418
8419/// Detection difficulty classification configuration.
8420#[derive(Debug, Clone, Serialize, Deserialize)]
8421pub struct DifficultyClassificationConfig {
8422    /// Enable detection difficulty classification.
8423    #[serde(default)]
8424    pub enabled: bool,
8425
8426    /// Target distribution of difficulty levels.
8427    #[serde(default)]
8428    pub target_distribution: DifficultyDistributionConfig,
8429}
8430
8431impl Default for DifficultyClassificationConfig {
8432    fn default() -> Self {
8433        Self {
8434            enabled: true,
8435            target_distribution: DifficultyDistributionConfig::default(),
8436        }
8437    }
8438}
8439
8440/// Target distribution of detection difficulty levels.
8441#[derive(Debug, Clone, Serialize, Deserialize)]
8442pub struct DifficultyDistributionConfig {
8443    /// Proportion of trivial anomalies (expected 99% detection).
8444    #[serde(default = "default_difficulty_trivial")]
8445    pub trivial: f64,
8446
8447    /// Proportion of easy anomalies (expected 90% detection).
8448    #[serde(default = "default_difficulty_easy")]
8449    pub easy: f64,
8450
8451    /// Proportion of moderate anomalies (expected 70% detection).
8452    #[serde(default = "default_difficulty_moderate")]
8453    pub moderate: f64,
8454
8455    /// Proportion of hard anomalies (expected 40% detection).
8456    #[serde(default = "default_difficulty_hard")]
8457    pub hard: f64,
8458
8459    /// Proportion of expert anomalies (expected 15% detection).
8460    #[serde(default = "default_difficulty_expert")]
8461    pub expert: f64,
8462}
8463
8464fn default_difficulty_trivial() -> f64 {
8465    0.15
8466}
8467fn default_difficulty_easy() -> f64 {
8468    0.25
8469}
8470fn default_difficulty_moderate() -> f64 {
8471    0.30
8472}
8473fn default_difficulty_hard() -> f64 {
8474    0.20
8475}
8476fn default_difficulty_expert() -> f64 {
8477    0.10
8478}
8479
8480impl Default for DifficultyDistributionConfig {
8481    fn default() -> Self {
8482        Self {
8483            trivial: default_difficulty_trivial(),
8484            easy: default_difficulty_easy(),
8485            moderate: default_difficulty_moderate(),
8486            hard: default_difficulty_hard(),
8487            expert: default_difficulty_expert(),
8488        }
8489    }
8490}
8491
8492/// Context-aware injection configuration.
8493#[derive(Debug, Clone, Serialize, Deserialize, Default)]
8494pub struct ContextAwareConfig {
8495    /// Enable context-aware injection.
8496    #[serde(default)]
8497    pub enabled: bool,
8498
8499    /// Vendor-specific anomaly rules.
8500    #[serde(default)]
8501    pub vendor_rules: VendorAnomalyRulesConfig,
8502
8503    /// Employee-specific anomaly rules.
8504    #[serde(default)]
8505    pub employee_rules: EmployeeAnomalyRulesConfig,
8506
8507    /// Account-specific anomaly rules.
8508    #[serde(default)]
8509    pub account_rules: AccountAnomalyRulesConfig,
8510
8511    /// Behavioral baseline configuration.
8512    #[serde(default)]
8513    pub behavioral_baseline: BehavioralBaselineConfig,
8514}
8515
8516/// Vendor-specific anomaly rules configuration.
8517#[derive(Debug, Clone, Serialize, Deserialize)]
8518pub struct VendorAnomalyRulesConfig {
8519    /// Error rate multiplier for new vendors (< threshold days).
8520    #[serde(default = "default_new_vendor_multiplier")]
8521    pub new_vendor_error_multiplier: f64,
8522
8523    /// Days threshold for "new" vendor classification.
8524    #[serde(default = "default_new_vendor_threshold")]
8525    pub new_vendor_threshold_days: u32,
8526
8527    /// Error rate multiplier for international vendors.
8528    #[serde(default = "default_international_multiplier")]
8529    pub international_error_multiplier: f64,
8530
8531    /// Strategic vendor anomaly types (may differ from general vendors).
8532    #[serde(default = "default_strategic_vendor_types")]
8533    pub strategic_vendor_anomaly_types: Vec<String>,
8534}
8535
8536fn default_new_vendor_multiplier() -> f64 {
8537    2.5
8538}
8539fn default_new_vendor_threshold() -> u32 {
8540    90
8541}
8542fn default_international_multiplier() -> f64 {
8543    1.5
8544}
8545fn default_strategic_vendor_types() -> Vec<String> {
8546    vec![
8547        "pricing_dispute".to_string(),
8548        "contract_violation".to_string(),
8549    ]
8550}
8551
8552impl Default for VendorAnomalyRulesConfig {
8553    fn default() -> Self {
8554        Self {
8555            new_vendor_error_multiplier: default_new_vendor_multiplier(),
8556            new_vendor_threshold_days: default_new_vendor_threshold(),
8557            international_error_multiplier: default_international_multiplier(),
8558            strategic_vendor_anomaly_types: default_strategic_vendor_types(),
8559        }
8560    }
8561}
8562
8563/// Employee-specific anomaly rules configuration.
8564#[derive(Debug, Clone, Serialize, Deserialize)]
8565pub struct EmployeeAnomalyRulesConfig {
8566    /// Error rate for new employees (< threshold days).
8567    #[serde(default = "default_new_employee_rate")]
8568    pub new_employee_error_rate: f64,
8569
8570    /// Days threshold for "new" employee classification.
8571    #[serde(default = "default_new_employee_threshold")]
8572    pub new_employee_threshold_days: u32,
8573
8574    /// Transaction volume threshold for fatigue errors.
8575    #[serde(default = "default_volume_fatigue_threshold")]
8576    pub volume_fatigue_threshold: u32,
8577
8578    /// Error rate multiplier when primary approver is absent.
8579    #[serde(default = "default_coverage_multiplier")]
8580    pub coverage_error_multiplier: f64,
8581}
8582
8583fn default_new_employee_rate() -> f64 {
8584    0.05
8585}
8586fn default_new_employee_threshold() -> u32 {
8587    180
8588}
8589fn default_volume_fatigue_threshold() -> u32 {
8590    50
8591}
8592fn default_coverage_multiplier() -> f64 {
8593    1.8
8594}
8595
8596impl Default for EmployeeAnomalyRulesConfig {
8597    fn default() -> Self {
8598        Self {
8599            new_employee_error_rate: default_new_employee_rate(),
8600            new_employee_threshold_days: default_new_employee_threshold(),
8601            volume_fatigue_threshold: default_volume_fatigue_threshold(),
8602            coverage_error_multiplier: default_coverage_multiplier(),
8603        }
8604    }
8605}
8606
8607/// Account-specific anomaly rules configuration.
8608#[derive(Debug, Clone, Serialize, Deserialize)]
8609pub struct AccountAnomalyRulesConfig {
8610    /// Error rate multiplier for high-risk accounts.
8611    #[serde(default = "default_high_risk_multiplier")]
8612    pub high_risk_account_multiplier: f64,
8613
8614    /// Account codes considered high-risk.
8615    #[serde(default = "default_high_risk_accounts")]
8616    pub high_risk_accounts: Vec<String>,
8617
8618    /// Error rate multiplier for suspense accounts.
8619    #[serde(default = "default_suspense_multiplier")]
8620    pub suspense_account_multiplier: f64,
8621
8622    /// Account codes considered suspense accounts.
8623    #[serde(default = "default_suspense_accounts")]
8624    pub suspense_accounts: Vec<String>,
8625
8626    /// Error rate multiplier for intercompany accounts.
8627    #[serde(default = "default_intercompany_multiplier")]
8628    pub intercompany_account_multiplier: f64,
8629}
8630
8631fn default_high_risk_multiplier() -> f64 {
8632    2.0
8633}
8634fn default_high_risk_accounts() -> Vec<String> {
8635    vec![
8636        "1100".to_string(), // AR Control
8637        "2000".to_string(), // AP Control
8638        "3000".to_string(), // Cash
8639    ]
8640}
8641fn default_suspense_multiplier() -> f64 {
8642    3.0
8643}
8644fn default_suspense_accounts() -> Vec<String> {
8645    vec!["9999".to_string(), "9998".to_string()]
8646}
8647fn default_intercompany_multiplier() -> f64 {
8648    1.5
8649}
8650
8651impl Default for AccountAnomalyRulesConfig {
8652    fn default() -> Self {
8653        Self {
8654            high_risk_account_multiplier: default_high_risk_multiplier(),
8655            high_risk_accounts: default_high_risk_accounts(),
8656            suspense_account_multiplier: default_suspense_multiplier(),
8657            suspense_accounts: default_suspense_accounts(),
8658            intercompany_account_multiplier: default_intercompany_multiplier(),
8659        }
8660    }
8661}
8662
8663/// Behavioral baseline configuration.
8664#[derive(Debug, Clone, Serialize, Deserialize)]
8665pub struct BehavioralBaselineConfig {
8666    /// Enable behavioral baseline tracking.
8667    #[serde(default)]
8668    pub enabled: bool,
8669
8670    /// Number of days to build baseline from.
8671    #[serde(default = "default_baseline_period")]
8672    pub baseline_period_days: u32,
8673
8674    /// Standard deviation threshold for amount anomalies.
8675    #[serde(default = "default_deviation_threshold")]
8676    pub deviation_threshold_std: f64,
8677
8678    /// Standard deviation threshold for frequency anomalies.
8679    #[serde(default = "default_frequency_deviation")]
8680    pub frequency_deviation_threshold: f64,
8681}
8682
8683fn default_baseline_period() -> u32 {
8684    90
8685}
8686fn default_deviation_threshold() -> f64 {
8687    3.0
8688}
8689fn default_frequency_deviation() -> f64 {
8690    2.0
8691}
8692
8693impl Default for BehavioralBaselineConfig {
8694    fn default() -> Self {
8695        Self {
8696            enabled: false,
8697            baseline_period_days: default_baseline_period(),
8698            deviation_threshold_std: default_deviation_threshold(),
8699            frequency_deviation_threshold: default_frequency_deviation(),
8700        }
8701    }
8702}
8703
8704/// Enhanced labeling configuration.
8705#[derive(Debug, Clone, Serialize, Deserialize)]
8706pub struct EnhancedLabelingConfig {
8707    /// Enable severity scoring.
8708    #[serde(default = "default_true_val")]
8709    pub severity_scoring: bool,
8710
8711    /// Enable difficulty classification.
8712    #[serde(default = "default_true_val")]
8713    pub difficulty_classification: bool,
8714
8715    /// Materiality thresholds for severity classification.
8716    #[serde(default)]
8717    pub materiality_thresholds: MaterialityThresholdsConfig,
8718}
8719
8720impl Default for EnhancedLabelingConfig {
8721    fn default() -> Self {
8722        Self {
8723            severity_scoring: true,
8724            difficulty_classification: true,
8725            materiality_thresholds: MaterialityThresholdsConfig::default(),
8726        }
8727    }
8728}
8729
8730/// Materiality thresholds configuration.
8731#[derive(Debug, Clone, Serialize, Deserialize)]
8732pub struct MaterialityThresholdsConfig {
8733    /// Threshold for trivial impact (as percentage of total).
8734    #[serde(default = "default_materiality_trivial")]
8735    pub trivial: f64,
8736
8737    /// Threshold for immaterial impact.
8738    #[serde(default = "default_materiality_immaterial")]
8739    pub immaterial: f64,
8740
8741    /// Threshold for material impact.
8742    #[serde(default = "default_materiality_material")]
8743    pub material: f64,
8744
8745    /// Threshold for highly material impact.
8746    #[serde(default = "default_materiality_highly_material")]
8747    pub highly_material: f64,
8748}
8749
8750fn default_materiality_trivial() -> f64 {
8751    0.001
8752}
8753fn default_materiality_immaterial() -> f64 {
8754    0.01
8755}
8756fn default_materiality_material() -> f64 {
8757    0.05
8758}
8759fn default_materiality_highly_material() -> f64 {
8760    0.10
8761}
8762
8763impl Default for MaterialityThresholdsConfig {
8764    fn default() -> Self {
8765        Self {
8766            trivial: default_materiality_trivial(),
8767            immaterial: default_materiality_immaterial(),
8768            material: default_materiality_material(),
8769            highly_material: default_materiality_highly_material(),
8770        }
8771    }
8772}
8773
8774// =============================================================================
8775// Industry-Specific Configuration
8776// =============================================================================
8777
8778/// Industry-specific transaction and anomaly generation configuration.
8779///
8780/// This configuration enables generation of industry-authentic:
8781/// - Transaction types with appropriate terminology
8782/// - Master data (BOM, routings, clinical codes, etc.)
8783/// - Industry-specific anomaly patterns
8784/// - Regulatory framework compliance
8785#[derive(Debug, Clone, Serialize, Deserialize, Default)]
8786pub struct IndustrySpecificConfig {
8787    /// Enable industry-specific generation.
8788    #[serde(default)]
8789    pub enabled: bool,
8790
8791    /// Manufacturing industry settings.
8792    #[serde(default)]
8793    pub manufacturing: ManufacturingConfig,
8794
8795    /// Retail industry settings.
8796    #[serde(default)]
8797    pub retail: RetailConfig,
8798
8799    /// Healthcare industry settings.
8800    #[serde(default)]
8801    pub healthcare: HealthcareConfig,
8802
8803    /// Technology industry settings.
8804    #[serde(default)]
8805    pub technology: TechnologyConfig,
8806
8807    /// Financial services industry settings.
8808    #[serde(default)]
8809    pub financial_services: FinancialServicesConfig,
8810
8811    /// Professional services industry settings.
8812    #[serde(default)]
8813    pub professional_services: ProfessionalServicesConfig,
8814}
8815
8816/// Manufacturing industry configuration.
8817#[derive(Debug, Clone, Serialize, Deserialize)]
8818pub struct ManufacturingConfig {
8819    /// Enable manufacturing-specific generation.
8820    #[serde(default)]
8821    pub enabled: bool,
8822
8823    /// Bill of Materials depth (typical: 3-7).
8824    #[serde(default = "default_bom_depth")]
8825    pub bom_depth: u32,
8826
8827    /// Whether to use just-in-time inventory.
8828    #[serde(default)]
8829    pub just_in_time: bool,
8830
8831    /// Production order types to generate.
8832    #[serde(default = "default_production_order_types")]
8833    pub production_order_types: Vec<String>,
8834
8835    /// Quality framework (ISO_9001, Six_Sigma, etc.).
8836    #[serde(default)]
8837    pub quality_framework: Option<String>,
8838
8839    /// Number of supplier tiers to model (1-3).
8840    #[serde(default = "default_supplier_tiers")]
8841    pub supplier_tiers: u32,
8842
8843    /// Standard cost update frequency.
8844    #[serde(default = "default_cost_frequency")]
8845    pub standard_cost_frequency: String,
8846
8847    /// Target yield rate (0.95-0.99 typical).
8848    #[serde(default = "default_yield_rate")]
8849    pub target_yield_rate: f64,
8850
8851    /// Scrap percentage threshold for alerts.
8852    #[serde(default = "default_scrap_threshold")]
8853    pub scrap_alert_threshold: f64,
8854
8855    /// Manufacturing anomaly injection rates.
8856    #[serde(default)]
8857    pub anomaly_rates: ManufacturingAnomalyRates,
8858}
8859
8860fn default_bom_depth() -> u32 {
8861    4
8862}
8863
8864fn default_production_order_types() -> Vec<String> {
8865    vec![
8866        "standard".to_string(),
8867        "rework".to_string(),
8868        "prototype".to_string(),
8869    ]
8870}
8871
8872fn default_supplier_tiers() -> u32 {
8873    2
8874}
8875
8876fn default_cost_frequency() -> String {
8877    "quarterly".to_string()
8878}
8879
8880fn default_yield_rate() -> f64 {
8881    0.97
8882}
8883
8884fn default_scrap_threshold() -> f64 {
8885    0.03
8886}
8887
8888impl Default for ManufacturingConfig {
8889    fn default() -> Self {
8890        Self {
8891            enabled: false,
8892            bom_depth: default_bom_depth(),
8893            just_in_time: false,
8894            production_order_types: default_production_order_types(),
8895            quality_framework: Some("ISO_9001".to_string()),
8896            supplier_tiers: default_supplier_tiers(),
8897            standard_cost_frequency: default_cost_frequency(),
8898            target_yield_rate: default_yield_rate(),
8899            scrap_alert_threshold: default_scrap_threshold(),
8900            anomaly_rates: ManufacturingAnomalyRates::default(),
8901        }
8902    }
8903}
8904
8905/// Manufacturing anomaly injection rates.
8906#[derive(Debug, Clone, Serialize, Deserialize)]
8907pub struct ManufacturingAnomalyRates {
8908    /// Yield manipulation rate.
8909    #[serde(default = "default_mfg_yield_rate")]
8910    pub yield_manipulation: f64,
8911
8912    /// Labor misallocation rate.
8913    #[serde(default = "default_mfg_labor_rate")]
8914    pub labor_misallocation: f64,
8915
8916    /// Phantom production rate.
8917    #[serde(default = "default_mfg_phantom_rate")]
8918    pub phantom_production: f64,
8919
8920    /// Standard cost manipulation rate.
8921    #[serde(default = "default_mfg_cost_rate")]
8922    pub standard_cost_manipulation: f64,
8923
8924    /// Inventory fraud rate.
8925    #[serde(default = "default_mfg_inventory_rate")]
8926    pub inventory_fraud: f64,
8927}
8928
8929fn default_mfg_yield_rate() -> f64 {
8930    0.015
8931}
8932
8933fn default_mfg_labor_rate() -> f64 {
8934    0.02
8935}
8936
8937fn default_mfg_phantom_rate() -> f64 {
8938    0.005
8939}
8940
8941fn default_mfg_cost_rate() -> f64 {
8942    0.01
8943}
8944
8945fn default_mfg_inventory_rate() -> f64 {
8946    0.008
8947}
8948
8949impl Default for ManufacturingAnomalyRates {
8950    fn default() -> Self {
8951        Self {
8952            yield_manipulation: default_mfg_yield_rate(),
8953            labor_misallocation: default_mfg_labor_rate(),
8954            phantom_production: default_mfg_phantom_rate(),
8955            standard_cost_manipulation: default_mfg_cost_rate(),
8956            inventory_fraud: default_mfg_inventory_rate(),
8957        }
8958    }
8959}
8960
8961/// Retail industry configuration.
8962#[derive(Debug, Clone, Serialize, Deserialize)]
8963pub struct RetailConfig {
8964    /// Enable retail-specific generation.
8965    #[serde(default)]
8966    pub enabled: bool,
8967
8968    /// Store type distribution.
8969    #[serde(default)]
8970    pub store_types: RetailStoreTypeConfig,
8971
8972    /// Average daily transactions per store.
8973    #[serde(default = "default_retail_daily_txns")]
8974    pub avg_daily_transactions: u32,
8975
8976    /// Enable loss prevention tracking.
8977    #[serde(default = "default_true")]
8978    pub loss_prevention: bool,
8979
8980    /// Shrinkage rate (0.01-0.03 typical).
8981    #[serde(default = "default_shrinkage_rate")]
8982    pub shrinkage_rate: f64,
8983
8984    /// Retail anomaly injection rates.
8985    #[serde(default)]
8986    pub anomaly_rates: RetailAnomalyRates,
8987}
8988
8989fn default_retail_daily_txns() -> u32 {
8990    500
8991}
8992
8993fn default_shrinkage_rate() -> f64 {
8994    0.015
8995}
8996
8997impl Default for RetailConfig {
8998    fn default() -> Self {
8999        Self {
9000            enabled: false,
9001            store_types: RetailStoreTypeConfig::default(),
9002            avg_daily_transactions: default_retail_daily_txns(),
9003            loss_prevention: true,
9004            shrinkage_rate: default_shrinkage_rate(),
9005            anomaly_rates: RetailAnomalyRates::default(),
9006        }
9007    }
9008}
9009
9010/// Retail store type distribution.
9011#[derive(Debug, Clone, Serialize, Deserialize)]
9012pub struct RetailStoreTypeConfig {
9013    /// Percentage of flagship stores.
9014    #[serde(default = "default_flagship_pct")]
9015    pub flagship: f64,
9016
9017    /// Percentage of regional stores.
9018    #[serde(default = "default_regional_pct")]
9019    pub regional: f64,
9020
9021    /// Percentage of outlet stores.
9022    #[serde(default = "default_outlet_pct")]
9023    pub outlet: f64,
9024
9025    /// Percentage of e-commerce.
9026    #[serde(default = "default_ecommerce_pct")]
9027    pub ecommerce: f64,
9028}
9029
9030fn default_flagship_pct() -> f64 {
9031    0.10
9032}
9033
9034fn default_regional_pct() -> f64 {
9035    0.50
9036}
9037
9038fn default_outlet_pct() -> f64 {
9039    0.25
9040}
9041
9042fn default_ecommerce_pct() -> f64 {
9043    0.15
9044}
9045
9046impl Default for RetailStoreTypeConfig {
9047    fn default() -> Self {
9048        Self {
9049            flagship: default_flagship_pct(),
9050            regional: default_regional_pct(),
9051            outlet: default_outlet_pct(),
9052            ecommerce: default_ecommerce_pct(),
9053        }
9054    }
9055}
9056
9057/// Retail anomaly injection rates.
9058#[derive(Debug, Clone, Serialize, Deserialize)]
9059pub struct RetailAnomalyRates {
9060    /// Sweethearting rate.
9061    #[serde(default = "default_sweethearting_rate")]
9062    pub sweethearting: f64,
9063
9064    /// Skimming rate.
9065    #[serde(default = "default_skimming_rate")]
9066    pub skimming: f64,
9067
9068    /// Refund fraud rate.
9069    #[serde(default = "default_refund_fraud_rate")]
9070    pub refund_fraud: f64,
9071
9072    /// Void abuse rate.
9073    #[serde(default = "default_void_abuse_rate")]
9074    pub void_abuse: f64,
9075
9076    /// Gift card fraud rate.
9077    #[serde(default = "default_gift_card_rate")]
9078    pub gift_card_fraud: f64,
9079
9080    /// Vendor kickback rate.
9081    #[serde(default = "default_retail_kickback_rate")]
9082    pub vendor_kickback: f64,
9083}
9084
9085fn default_sweethearting_rate() -> f64 {
9086    0.02
9087}
9088
9089fn default_skimming_rate() -> f64 {
9090    0.005
9091}
9092
9093fn default_refund_fraud_rate() -> f64 {
9094    0.015
9095}
9096
9097fn default_void_abuse_rate() -> f64 {
9098    0.01
9099}
9100
9101fn default_gift_card_rate() -> f64 {
9102    0.008
9103}
9104
9105fn default_retail_kickback_rate() -> f64 {
9106    0.003
9107}
9108
9109impl Default for RetailAnomalyRates {
9110    fn default() -> Self {
9111        Self {
9112            sweethearting: default_sweethearting_rate(),
9113            skimming: default_skimming_rate(),
9114            refund_fraud: default_refund_fraud_rate(),
9115            void_abuse: default_void_abuse_rate(),
9116            gift_card_fraud: default_gift_card_rate(),
9117            vendor_kickback: default_retail_kickback_rate(),
9118        }
9119    }
9120}
9121
9122/// Healthcare industry configuration.
9123#[derive(Debug, Clone, Serialize, Deserialize)]
9124pub struct HealthcareConfig {
9125    /// Enable healthcare-specific generation.
9126    #[serde(default)]
9127    pub enabled: bool,
9128
9129    /// Healthcare facility type.
9130    #[serde(default = "default_facility_type")]
9131    pub facility_type: String,
9132
9133    /// Payer mix distribution.
9134    #[serde(default)]
9135    pub payer_mix: HealthcarePayerMix,
9136
9137    /// Coding systems enabled.
9138    #[serde(default)]
9139    pub coding_systems: HealthcareCodingSystems,
9140
9141    /// Healthcare compliance settings.
9142    #[serde(default)]
9143    pub compliance: HealthcareComplianceConfig,
9144
9145    /// Average daily encounters.
9146    #[serde(default = "default_daily_encounters")]
9147    pub avg_daily_encounters: u32,
9148
9149    /// Average charges per encounter.
9150    #[serde(default = "default_charges_per_encounter")]
9151    pub avg_charges_per_encounter: u32,
9152
9153    /// Denial rate (0.0-1.0).
9154    #[serde(default = "default_hc_denial_rate")]
9155    pub denial_rate: f64,
9156
9157    /// Bad debt rate (0.0-1.0).
9158    #[serde(default = "default_hc_bad_debt_rate")]
9159    pub bad_debt_rate: f64,
9160
9161    /// Charity care rate (0.0-1.0).
9162    #[serde(default = "default_hc_charity_care_rate")]
9163    pub charity_care_rate: f64,
9164
9165    /// Healthcare anomaly injection rates.
9166    #[serde(default)]
9167    pub anomaly_rates: HealthcareAnomalyRates,
9168}
9169
9170fn default_facility_type() -> String {
9171    "hospital".to_string()
9172}
9173
9174fn default_daily_encounters() -> u32 {
9175    150
9176}
9177
9178fn default_charges_per_encounter() -> u32 {
9179    8
9180}
9181
9182fn default_hc_denial_rate() -> f64 {
9183    0.05
9184}
9185
9186fn default_hc_bad_debt_rate() -> f64 {
9187    0.03
9188}
9189
9190fn default_hc_charity_care_rate() -> f64 {
9191    0.02
9192}
9193
9194impl Default for HealthcareConfig {
9195    fn default() -> Self {
9196        Self {
9197            enabled: false,
9198            facility_type: default_facility_type(),
9199            payer_mix: HealthcarePayerMix::default(),
9200            coding_systems: HealthcareCodingSystems::default(),
9201            compliance: HealthcareComplianceConfig::default(),
9202            avg_daily_encounters: default_daily_encounters(),
9203            avg_charges_per_encounter: default_charges_per_encounter(),
9204            denial_rate: default_hc_denial_rate(),
9205            bad_debt_rate: default_hc_bad_debt_rate(),
9206            charity_care_rate: default_hc_charity_care_rate(),
9207            anomaly_rates: HealthcareAnomalyRates::default(),
9208        }
9209    }
9210}
9211
9212/// Healthcare payer mix distribution.
9213#[derive(Debug, Clone, Serialize, Deserialize)]
9214pub struct HealthcarePayerMix {
9215    /// Medicare percentage.
9216    #[serde(default = "default_medicare_pct")]
9217    pub medicare: f64,
9218
9219    /// Medicaid percentage.
9220    #[serde(default = "default_medicaid_pct")]
9221    pub medicaid: f64,
9222
9223    /// Commercial insurance percentage.
9224    #[serde(default = "default_commercial_pct")]
9225    pub commercial: f64,
9226
9227    /// Self-pay percentage.
9228    #[serde(default = "default_self_pay_pct")]
9229    pub self_pay: f64,
9230}
9231
9232fn default_medicare_pct() -> f64 {
9233    0.40
9234}
9235
9236fn default_medicaid_pct() -> f64 {
9237    0.20
9238}
9239
9240fn default_commercial_pct() -> f64 {
9241    0.30
9242}
9243
9244fn default_self_pay_pct() -> f64 {
9245    0.10
9246}
9247
9248impl Default for HealthcarePayerMix {
9249    fn default() -> Self {
9250        Self {
9251            medicare: default_medicare_pct(),
9252            medicaid: default_medicaid_pct(),
9253            commercial: default_commercial_pct(),
9254            self_pay: default_self_pay_pct(),
9255        }
9256    }
9257}
9258
9259/// Healthcare coding systems configuration.
9260#[derive(Debug, Clone, Serialize, Deserialize)]
9261pub struct HealthcareCodingSystems {
9262    /// Enable ICD-10 diagnosis coding.
9263    #[serde(default = "default_true")]
9264    pub icd10: bool,
9265
9266    /// Enable CPT procedure coding.
9267    #[serde(default = "default_true")]
9268    pub cpt: bool,
9269
9270    /// Enable DRG grouping.
9271    #[serde(default = "default_true")]
9272    pub drg: bool,
9273
9274    /// Enable HCPCS Level II coding.
9275    #[serde(default = "default_true")]
9276    pub hcpcs: bool,
9277
9278    /// Enable revenue codes.
9279    #[serde(default = "default_true")]
9280    pub revenue_codes: bool,
9281}
9282
9283impl Default for HealthcareCodingSystems {
9284    fn default() -> Self {
9285        Self {
9286            icd10: true,
9287            cpt: true,
9288            drg: true,
9289            hcpcs: true,
9290            revenue_codes: true,
9291        }
9292    }
9293}
9294
9295/// Healthcare compliance configuration.
9296#[derive(Debug, Clone, Serialize, Deserialize)]
9297pub struct HealthcareComplianceConfig {
9298    /// Enable HIPAA compliance.
9299    #[serde(default = "default_true")]
9300    pub hipaa: bool,
9301
9302    /// Enable Stark Law compliance.
9303    #[serde(default = "default_true")]
9304    pub stark_law: bool,
9305
9306    /// Enable Anti-Kickback Statute compliance.
9307    #[serde(default = "default_true")]
9308    pub anti_kickback: bool,
9309
9310    /// Enable False Claims Act compliance.
9311    #[serde(default = "default_true")]
9312    pub false_claims_act: bool,
9313
9314    /// Enable EMTALA compliance (for hospitals).
9315    #[serde(default = "default_true")]
9316    pub emtala: bool,
9317}
9318
9319impl Default for HealthcareComplianceConfig {
9320    fn default() -> Self {
9321        Self {
9322            hipaa: true,
9323            stark_law: true,
9324            anti_kickback: true,
9325            false_claims_act: true,
9326            emtala: true,
9327        }
9328    }
9329}
9330
9331/// Healthcare anomaly injection rates.
9332#[derive(Debug, Clone, Serialize, Deserialize)]
9333pub struct HealthcareAnomalyRates {
9334    /// Upcoding rate.
9335    #[serde(default = "default_upcoding_rate")]
9336    pub upcoding: f64,
9337
9338    /// Unbundling rate.
9339    #[serde(default = "default_unbundling_rate")]
9340    pub unbundling: f64,
9341
9342    /// Phantom billing rate.
9343    #[serde(default = "default_phantom_billing_rate")]
9344    pub phantom_billing: f64,
9345
9346    /// Kickback rate.
9347    #[serde(default = "default_healthcare_kickback_rate")]
9348    pub kickbacks: f64,
9349
9350    /// Duplicate billing rate.
9351    #[serde(default = "default_duplicate_billing_rate")]
9352    pub duplicate_billing: f64,
9353
9354    /// Medical necessity abuse rate.
9355    #[serde(default = "default_med_necessity_rate")]
9356    pub medical_necessity_abuse: f64,
9357}
9358
9359fn default_upcoding_rate() -> f64 {
9360    0.02
9361}
9362
9363fn default_unbundling_rate() -> f64 {
9364    0.015
9365}
9366
9367fn default_phantom_billing_rate() -> f64 {
9368    0.005
9369}
9370
9371fn default_healthcare_kickback_rate() -> f64 {
9372    0.003
9373}
9374
9375fn default_duplicate_billing_rate() -> f64 {
9376    0.008
9377}
9378
9379fn default_med_necessity_rate() -> f64 {
9380    0.01
9381}
9382
9383impl Default for HealthcareAnomalyRates {
9384    fn default() -> Self {
9385        Self {
9386            upcoding: default_upcoding_rate(),
9387            unbundling: default_unbundling_rate(),
9388            phantom_billing: default_phantom_billing_rate(),
9389            kickbacks: default_healthcare_kickback_rate(),
9390            duplicate_billing: default_duplicate_billing_rate(),
9391            medical_necessity_abuse: default_med_necessity_rate(),
9392        }
9393    }
9394}
9395
9396/// Technology industry configuration.
9397#[derive(Debug, Clone, Serialize, Deserialize)]
9398pub struct TechnologyConfig {
9399    /// Enable technology-specific generation.
9400    #[serde(default)]
9401    pub enabled: bool,
9402
9403    /// Revenue model type.
9404    #[serde(default = "default_revenue_model")]
9405    pub revenue_model: String,
9406
9407    /// Subscription revenue percentage (for SaaS).
9408    #[serde(default = "default_subscription_pct")]
9409    pub subscription_revenue_pct: f64,
9410
9411    /// License revenue percentage.
9412    #[serde(default = "default_license_pct")]
9413    pub license_revenue_pct: f64,
9414
9415    /// Services revenue percentage.
9416    #[serde(default = "default_services_pct")]
9417    pub services_revenue_pct: f64,
9418
9419    /// R&D capitalization settings.
9420    #[serde(default)]
9421    pub rd_capitalization: RdCapitalizationConfig,
9422
9423    /// Technology anomaly injection rates.
9424    #[serde(default)]
9425    pub anomaly_rates: TechnologyAnomalyRates,
9426}
9427
9428fn default_revenue_model() -> String {
9429    "saas".to_string()
9430}
9431
9432fn default_subscription_pct() -> f64 {
9433    0.60
9434}
9435
9436fn default_license_pct() -> f64 {
9437    0.25
9438}
9439
9440fn default_services_pct() -> f64 {
9441    0.15
9442}
9443
9444impl Default for TechnologyConfig {
9445    fn default() -> Self {
9446        Self {
9447            enabled: false,
9448            revenue_model: default_revenue_model(),
9449            subscription_revenue_pct: default_subscription_pct(),
9450            license_revenue_pct: default_license_pct(),
9451            services_revenue_pct: default_services_pct(),
9452            rd_capitalization: RdCapitalizationConfig::default(),
9453            anomaly_rates: TechnologyAnomalyRates::default(),
9454        }
9455    }
9456}
9457
9458/// R&D capitalization configuration.
9459#[derive(Debug, Clone, Serialize, Deserialize)]
9460pub struct RdCapitalizationConfig {
9461    /// Enable R&D capitalization.
9462    #[serde(default = "default_true")]
9463    pub enabled: bool,
9464
9465    /// Capitalization rate (0.0-1.0).
9466    #[serde(default = "default_cap_rate")]
9467    pub capitalization_rate: f64,
9468
9469    /// Useful life in years.
9470    #[serde(default = "default_useful_life")]
9471    pub useful_life_years: u32,
9472}
9473
9474fn default_cap_rate() -> f64 {
9475    0.30
9476}
9477
9478fn default_useful_life() -> u32 {
9479    3
9480}
9481
9482impl Default for RdCapitalizationConfig {
9483    fn default() -> Self {
9484        Self {
9485            enabled: true,
9486            capitalization_rate: default_cap_rate(),
9487            useful_life_years: default_useful_life(),
9488        }
9489    }
9490}
9491
9492/// Technology anomaly injection rates.
9493#[derive(Debug, Clone, Serialize, Deserialize)]
9494pub struct TechnologyAnomalyRates {
9495    /// Premature revenue recognition rate.
9496    #[serde(default = "default_premature_rev_rate")]
9497    pub premature_revenue: f64,
9498
9499    /// Side letter abuse rate.
9500    #[serde(default = "default_side_letter_rate")]
9501    pub side_letter_abuse: f64,
9502
9503    /// Channel stuffing rate.
9504    #[serde(default = "default_channel_stuffing_rate")]
9505    pub channel_stuffing: f64,
9506
9507    /// Improper capitalization rate.
9508    #[serde(default = "default_improper_cap_rate")]
9509    pub improper_capitalization: f64,
9510}
9511
9512fn default_premature_rev_rate() -> f64 {
9513    0.015
9514}
9515
9516fn default_side_letter_rate() -> f64 {
9517    0.008
9518}
9519
9520fn default_channel_stuffing_rate() -> f64 {
9521    0.01
9522}
9523
9524fn default_improper_cap_rate() -> f64 {
9525    0.012
9526}
9527
9528impl Default for TechnologyAnomalyRates {
9529    fn default() -> Self {
9530        Self {
9531            premature_revenue: default_premature_rev_rate(),
9532            side_letter_abuse: default_side_letter_rate(),
9533            channel_stuffing: default_channel_stuffing_rate(),
9534            improper_capitalization: default_improper_cap_rate(),
9535        }
9536    }
9537}
9538
9539/// Financial services industry configuration.
9540#[derive(Debug, Clone, Serialize, Deserialize)]
9541pub struct FinancialServicesConfig {
9542    /// Enable financial services-specific generation.
9543    #[serde(default)]
9544    pub enabled: bool,
9545
9546    /// Financial institution type.
9547    #[serde(default = "default_fi_type")]
9548    pub institution_type: String,
9549
9550    /// Regulatory framework.
9551    #[serde(default = "default_fi_regulatory")]
9552    pub regulatory_framework: String,
9553
9554    /// Financial services anomaly injection rates.
9555    #[serde(default)]
9556    pub anomaly_rates: FinancialServicesAnomalyRates,
9557}
9558
9559fn default_fi_type() -> String {
9560    "commercial_bank".to_string()
9561}
9562
9563fn default_fi_regulatory() -> String {
9564    "us_banking".to_string()
9565}
9566
9567impl Default for FinancialServicesConfig {
9568    fn default() -> Self {
9569        Self {
9570            enabled: false,
9571            institution_type: default_fi_type(),
9572            regulatory_framework: default_fi_regulatory(),
9573            anomaly_rates: FinancialServicesAnomalyRates::default(),
9574        }
9575    }
9576}
9577
9578/// Financial services anomaly injection rates.
9579#[derive(Debug, Clone, Serialize, Deserialize)]
9580pub struct FinancialServicesAnomalyRates {
9581    /// Loan fraud rate.
9582    #[serde(default = "default_loan_fraud_rate")]
9583    pub loan_fraud: f64,
9584
9585    /// Trading fraud rate.
9586    #[serde(default = "default_trading_fraud_rate")]
9587    pub trading_fraud: f64,
9588
9589    /// Insurance fraud rate.
9590    #[serde(default = "default_insurance_fraud_rate")]
9591    pub insurance_fraud: f64,
9592
9593    /// Account manipulation rate.
9594    #[serde(default = "default_account_manip_rate")]
9595    pub account_manipulation: f64,
9596}
9597
9598fn default_loan_fraud_rate() -> f64 {
9599    0.01
9600}
9601
9602fn default_trading_fraud_rate() -> f64 {
9603    0.008
9604}
9605
9606fn default_insurance_fraud_rate() -> f64 {
9607    0.012
9608}
9609
9610fn default_account_manip_rate() -> f64 {
9611    0.005
9612}
9613
9614impl Default for FinancialServicesAnomalyRates {
9615    fn default() -> Self {
9616        Self {
9617            loan_fraud: default_loan_fraud_rate(),
9618            trading_fraud: default_trading_fraud_rate(),
9619            insurance_fraud: default_insurance_fraud_rate(),
9620            account_manipulation: default_account_manip_rate(),
9621        }
9622    }
9623}
9624
9625/// Professional services industry configuration.
9626#[derive(Debug, Clone, Serialize, Deserialize)]
9627pub struct ProfessionalServicesConfig {
9628    /// Enable professional services-specific generation.
9629    #[serde(default)]
9630    pub enabled: bool,
9631
9632    /// Firm type.
9633    #[serde(default = "default_firm_type")]
9634    pub firm_type: String,
9635
9636    /// Billing model.
9637    #[serde(default = "default_billing_model")]
9638    pub billing_model: String,
9639
9640    /// Average hourly rate.
9641    #[serde(default = "default_hourly_rate")]
9642    pub avg_hourly_rate: f64,
9643
9644    /// Trust account settings (for law firms).
9645    #[serde(default)]
9646    pub trust_accounting: TrustAccountingConfig,
9647
9648    /// Professional services anomaly injection rates.
9649    #[serde(default)]
9650    pub anomaly_rates: ProfessionalServicesAnomalyRates,
9651}
9652
9653fn default_firm_type() -> String {
9654    "consulting".to_string()
9655}
9656
9657fn default_billing_model() -> String {
9658    "time_and_materials".to_string()
9659}
9660
9661fn default_hourly_rate() -> f64 {
9662    250.0
9663}
9664
9665impl Default for ProfessionalServicesConfig {
9666    fn default() -> Self {
9667        Self {
9668            enabled: false,
9669            firm_type: default_firm_type(),
9670            billing_model: default_billing_model(),
9671            avg_hourly_rate: default_hourly_rate(),
9672            trust_accounting: TrustAccountingConfig::default(),
9673            anomaly_rates: ProfessionalServicesAnomalyRates::default(),
9674        }
9675    }
9676}
9677
9678/// Trust accounting configuration for law firms.
9679#[derive(Debug, Clone, Serialize, Deserialize)]
9680pub struct TrustAccountingConfig {
9681    /// Enable trust accounting.
9682    #[serde(default)]
9683    pub enabled: bool,
9684
9685    /// Require three-way reconciliation.
9686    #[serde(default = "default_true")]
9687    pub require_three_way_reconciliation: bool,
9688}
9689
9690impl Default for TrustAccountingConfig {
9691    fn default() -> Self {
9692        Self {
9693            enabled: false,
9694            require_three_way_reconciliation: true,
9695        }
9696    }
9697}
9698
9699/// Professional services anomaly injection rates.
9700#[derive(Debug, Clone, Serialize, Deserialize)]
9701pub struct ProfessionalServicesAnomalyRates {
9702    /// Time billing fraud rate.
9703    #[serde(default = "default_time_fraud_rate")]
9704    pub time_billing_fraud: f64,
9705
9706    /// Expense report fraud rate.
9707    #[serde(default = "default_expense_fraud_rate")]
9708    pub expense_fraud: f64,
9709
9710    /// Trust misappropriation rate.
9711    #[serde(default = "default_trust_misappropriation_rate")]
9712    pub trust_misappropriation: f64,
9713}
9714
9715fn default_time_fraud_rate() -> f64 {
9716    0.02
9717}
9718
9719fn default_expense_fraud_rate() -> f64 {
9720    0.015
9721}
9722
9723fn default_trust_misappropriation_rate() -> f64 {
9724    0.003
9725}
9726
9727impl Default for ProfessionalServicesAnomalyRates {
9728    fn default() -> Self {
9729        Self {
9730            time_billing_fraud: default_time_fraud_rate(),
9731            expense_fraud: default_expense_fraud_rate(),
9732            trust_misappropriation: default_trust_misappropriation_rate(),
9733        }
9734    }
9735}
9736
9737/// Fingerprint privacy configuration for extraction and synthesis.
9738///
9739/// Controls the privacy parameters used when extracting fingerprints
9740/// from sensitive data. Supports predefined levels or custom (epsilon, delta) tuples.
9741///
9742/// ```yaml
9743/// fingerprint_privacy:
9744///   level: custom
9745///   epsilon: 0.5
9746///   delta: 1.0e-5
9747///   k_anonymity: 10
9748///   composition_method: renyi_dp
9749/// ```
9750#[derive(Debug, Clone, Serialize, Deserialize)]
9751pub struct FingerprintPrivacyConfig {
9752    /// Privacy level preset. Use "custom" for user-specified epsilon/delta.
9753    #[serde(default)]
9754    pub level: String,
9755    /// Custom epsilon value (only used when level = "custom").
9756    #[serde(default = "default_epsilon")]
9757    pub epsilon: f64,
9758    /// Custom delta value for (epsilon, delta)-DP (only used with RDP/zCDP).
9759    #[serde(default = "default_delta")]
9760    pub delta: f64,
9761    /// K-anonymity threshold.
9762    #[serde(default = "default_k_anonymity")]
9763    pub k_anonymity: u32,
9764    /// Composition method: "naive", "advanced", "renyi_dp", "zcdp".
9765    #[serde(default)]
9766    pub composition_method: String,
9767}
9768
9769fn default_epsilon() -> f64 {
9770    1.0
9771}
9772
9773fn default_delta() -> f64 {
9774    1e-5
9775}
9776
9777fn default_k_anonymity() -> u32 {
9778    5
9779}
9780
9781impl Default for FingerprintPrivacyConfig {
9782    fn default() -> Self {
9783        Self {
9784            level: "standard".to_string(),
9785            epsilon: default_epsilon(),
9786            delta: default_delta(),
9787            k_anonymity: default_k_anonymity(),
9788            composition_method: "naive".to_string(),
9789        }
9790    }
9791}
9792
9793/// Quality gates configuration for pass/fail thresholds on generation runs.
9794///
9795/// ```yaml
9796/// quality_gates:
9797///   enabled: true
9798///   profile: strict  # strict, default, lenient, custom
9799///   fail_on_violation: true
9800///   custom_gates:
9801///     - name: benford_compliance
9802///       metric: benford_mad
9803///       threshold: 0.015
9804///       comparison: lte
9805/// ```
9806#[derive(Debug, Clone, Serialize, Deserialize)]
9807pub struct QualityGatesSchemaConfig {
9808    /// Enable quality gate evaluation.
9809    #[serde(default)]
9810    pub enabled: bool,
9811    /// Gate profile: "strict", "default", "lenient", or "custom".
9812    #[serde(default = "default_gate_profile_name")]
9813    pub profile: String,
9814    /// Whether to fail the generation on gate violations.
9815    #[serde(default)]
9816    pub fail_on_violation: bool,
9817    /// Custom gate definitions (used when profile = "custom").
9818    #[serde(default)]
9819    pub custom_gates: Vec<QualityGateEntry>,
9820}
9821
9822fn default_gate_profile_name() -> String {
9823    "default".to_string()
9824}
9825
9826impl Default for QualityGatesSchemaConfig {
9827    fn default() -> Self {
9828        Self {
9829            enabled: false,
9830            profile: default_gate_profile_name(),
9831            fail_on_violation: false,
9832            custom_gates: Vec::new(),
9833        }
9834    }
9835}
9836
9837/// A single quality gate entry in configuration.
9838#[derive(Debug, Clone, Serialize, Deserialize)]
9839pub struct QualityGateEntry {
9840    /// Gate name.
9841    pub name: String,
9842    /// Metric to check: benford_mad, balance_coherence, document_chain_integrity,
9843    /// correlation_preservation, temporal_consistency, privacy_mia_auc,
9844    /// completion_rate, duplicate_rate, referential_integrity, ic_match_rate.
9845    pub metric: String,
9846    /// Threshold value.
9847    pub threshold: f64,
9848    /// Upper threshold for "between" comparison.
9849    #[serde(default)]
9850    pub upper_threshold: Option<f64>,
9851    /// Comparison operator: "gte", "lte", "eq", "between".
9852    #[serde(default = "default_gate_comparison")]
9853    pub comparison: String,
9854}
9855
9856fn default_gate_comparison() -> String {
9857    "gte".to_string()
9858}
9859
9860/// Compliance configuration for regulatory requirements.
9861///
9862/// ```yaml
9863/// compliance:
9864///   content_marking:
9865///     enabled: true
9866///     format: embedded  # embedded, sidecar, both
9867///   article10_report: true
9868/// ```
9869#[derive(Debug, Clone, Default, Serialize, Deserialize)]
9870pub struct ComplianceSchemaConfig {
9871    /// Synthetic content marking configuration (EU AI Act Article 50).
9872    #[serde(default)]
9873    pub content_marking: ContentMarkingSchemaConfig,
9874    /// Generate Article 10 data governance report.
9875    #[serde(default)]
9876    pub article10_report: bool,
9877    /// Certificate configuration for proving DP guarantees.
9878    #[serde(default)]
9879    pub certificates: CertificateSchemaConfig,
9880}
9881
9882/// Configuration for synthetic data certificates.
9883#[derive(Debug, Clone, Default, Serialize, Deserialize)]
9884pub struct CertificateSchemaConfig {
9885    /// Whether certificate generation is enabled.
9886    #[serde(default)]
9887    pub enabled: bool,
9888    /// Environment variable name for the signing key.
9889    #[serde(default)]
9890    pub signing_key_env: Option<String>,
9891    /// Whether to include quality metrics in the certificate.
9892    #[serde(default)]
9893    pub include_quality_metrics: bool,
9894}
9895
9896/// Content marking configuration for synthetic data output.
9897#[derive(Debug, Clone, Serialize, Deserialize)]
9898pub struct ContentMarkingSchemaConfig {
9899    /// Whether content marking is enabled.
9900    #[serde(default = "default_true")]
9901    pub enabled: bool,
9902    /// Marking format: "embedded", "sidecar", or "both".
9903    #[serde(default = "default_marking_format")]
9904    pub format: String,
9905}
9906
9907fn default_marking_format() -> String {
9908    "embedded".to_string()
9909}
9910
9911impl Default for ContentMarkingSchemaConfig {
9912    fn default() -> Self {
9913        Self {
9914            enabled: true,
9915            format: default_marking_format(),
9916        }
9917    }
9918}
9919
9920/// Webhook notification configuration.
9921#[derive(Debug, Clone, Default, Serialize, Deserialize)]
9922pub struct WebhookSchemaConfig {
9923    /// Whether webhooks are enabled.
9924    #[serde(default)]
9925    pub enabled: bool,
9926    /// Webhook endpoint configurations.
9927    #[serde(default)]
9928    pub endpoints: Vec<WebhookEndpointConfig>,
9929}
9930
9931/// Configuration for a single webhook endpoint.
9932#[derive(Debug, Clone, Serialize, Deserialize)]
9933pub struct WebhookEndpointConfig {
9934    /// Target URL for the webhook.
9935    pub url: String,
9936    /// Event types this endpoint subscribes to.
9937    #[serde(default)]
9938    pub events: Vec<String>,
9939    /// Optional secret for HMAC-SHA256 signature.
9940    #[serde(default)]
9941    pub secret: Option<String>,
9942    /// Maximum retry attempts (default: 3).
9943    #[serde(default = "default_webhook_retries")]
9944    pub max_retries: u32,
9945    /// Timeout in seconds (default: 10).
9946    #[serde(default = "default_webhook_timeout")]
9947    pub timeout_secs: u64,
9948}
9949
9950fn default_webhook_retries() -> u32 {
9951    3
9952}
9953fn default_webhook_timeout() -> u64 {
9954    10
9955}
9956
9957// ===== Enterprise Process Chain Config Structs =====
9958
9959// ----- Source-to-Pay (S2C/S2P) -----
9960
9961/// Source-to-Pay configuration covering the entire sourcing lifecycle.
9962#[derive(Debug, Clone, Default, Serialize, Deserialize)]
9963pub struct SourceToPayConfig {
9964    /// Enable source-to-pay generation
9965    #[serde(default)]
9966    pub enabled: bool,
9967    /// Spend analysis configuration
9968    #[serde(default)]
9969    pub spend_analysis: SpendAnalysisConfig,
9970    /// Sourcing project configuration
9971    #[serde(default)]
9972    pub sourcing: SourcingConfig,
9973    /// Supplier qualification configuration
9974    #[serde(default)]
9975    pub qualification: QualificationConfig,
9976    /// RFx event configuration
9977    #[serde(default)]
9978    pub rfx: RfxConfig,
9979    /// Contract configuration
9980    #[serde(default)]
9981    pub contracts: ContractConfig,
9982    /// Catalog configuration
9983    #[serde(default)]
9984    pub catalog: CatalogConfig,
9985    /// Scorecard configuration
9986    #[serde(default)]
9987    pub scorecards: ScorecardConfig,
9988    /// P2P integration settings
9989    #[serde(default)]
9990    pub p2p_integration: P2PIntegrationConfig,
9991}
9992
9993/// Spend analysis configuration.
9994#[derive(Debug, Clone, Serialize, Deserialize)]
9995pub struct SpendAnalysisConfig {
9996    /// HHI threshold for triggering sourcing project
9997    #[serde(default = "default_hhi_threshold")]
9998    pub hhi_threshold: f64,
9999    /// Target spend coverage under contracts
10000    #[serde(default = "default_contract_coverage_target")]
10001    pub contract_coverage_target: f64,
10002}
10003
10004impl Default for SpendAnalysisConfig {
10005    fn default() -> Self {
10006        Self {
10007            hhi_threshold: default_hhi_threshold(),
10008            contract_coverage_target: default_contract_coverage_target(),
10009        }
10010    }
10011}
10012
10013fn default_hhi_threshold() -> f64 {
10014    2500.0
10015}
10016fn default_contract_coverage_target() -> f64 {
10017    0.80
10018}
10019
10020/// Sourcing project configuration.
10021#[derive(Debug, Clone, Serialize, Deserialize)]
10022pub struct SourcingConfig {
10023    /// Number of sourcing projects per year
10024    #[serde(default = "default_sourcing_projects_per_year")]
10025    pub projects_per_year: u32,
10026    /// Months before expiry to trigger renewal project
10027    #[serde(default = "default_renewal_horizon_months")]
10028    pub renewal_horizon_months: u32,
10029    /// Average project duration in months
10030    #[serde(default = "default_project_duration_months")]
10031    pub project_duration_months: u32,
10032}
10033
10034impl Default for SourcingConfig {
10035    fn default() -> Self {
10036        Self {
10037            projects_per_year: default_sourcing_projects_per_year(),
10038            renewal_horizon_months: default_renewal_horizon_months(),
10039            project_duration_months: default_project_duration_months(),
10040        }
10041    }
10042}
10043
10044fn default_sourcing_projects_per_year() -> u32 {
10045    10
10046}
10047fn default_renewal_horizon_months() -> u32 {
10048    3
10049}
10050fn default_project_duration_months() -> u32 {
10051    4
10052}
10053
10054/// Supplier qualification configuration.
10055#[derive(Debug, Clone, Serialize, Deserialize)]
10056pub struct QualificationConfig {
10057    /// Pass rate for qualification
10058    #[serde(default = "default_qualification_pass_rate")]
10059    pub pass_rate: f64,
10060    /// Qualification validity in days
10061    #[serde(default = "default_qualification_validity_days")]
10062    pub validity_days: u32,
10063    /// Financial stability weight
10064    #[serde(default = "default_financial_weight")]
10065    pub financial_weight: f64,
10066    /// Quality management weight
10067    #[serde(default = "default_quality_weight")]
10068    pub quality_weight: f64,
10069    /// Delivery performance weight
10070    #[serde(default = "default_delivery_weight")]
10071    pub delivery_weight: f64,
10072    /// Compliance weight
10073    #[serde(default = "default_compliance_weight")]
10074    pub compliance_weight: f64,
10075}
10076
10077impl Default for QualificationConfig {
10078    fn default() -> Self {
10079        Self {
10080            pass_rate: default_qualification_pass_rate(),
10081            validity_days: default_qualification_validity_days(),
10082            financial_weight: default_financial_weight(),
10083            quality_weight: default_quality_weight(),
10084            delivery_weight: default_delivery_weight(),
10085            compliance_weight: default_compliance_weight(),
10086        }
10087    }
10088}
10089
10090fn default_qualification_pass_rate() -> f64 {
10091    0.75
10092}
10093fn default_qualification_validity_days() -> u32 {
10094    365
10095}
10096fn default_financial_weight() -> f64 {
10097    0.25
10098}
10099fn default_quality_weight() -> f64 {
10100    0.30
10101}
10102fn default_delivery_weight() -> f64 {
10103    0.25
10104}
10105fn default_compliance_weight() -> f64 {
10106    0.20
10107}
10108
10109/// RFx event configuration.
10110#[derive(Debug, Clone, Serialize, Deserialize)]
10111pub struct RfxConfig {
10112    /// Spend threshold above which RFI is required before RFP
10113    #[serde(default = "default_rfi_threshold")]
10114    pub rfi_threshold: f64,
10115    /// Minimum vendors invited per RFx
10116    #[serde(default = "default_min_invited_vendors")]
10117    pub min_invited_vendors: u32,
10118    /// Maximum vendors invited per RFx
10119    #[serde(default = "default_max_invited_vendors")]
10120    pub max_invited_vendors: u32,
10121    /// Response rate (% of invited vendors that submit bids)
10122    #[serde(default = "default_response_rate")]
10123    pub response_rate: f64,
10124    /// Default price weight in evaluation
10125    #[serde(default = "default_price_weight")]
10126    pub default_price_weight: f64,
10127    /// Default quality weight in evaluation
10128    #[serde(default = "default_rfx_quality_weight")]
10129    pub default_quality_weight: f64,
10130    /// Default delivery weight in evaluation
10131    #[serde(default = "default_rfx_delivery_weight")]
10132    pub default_delivery_weight: f64,
10133}
10134
10135impl Default for RfxConfig {
10136    fn default() -> Self {
10137        Self {
10138            rfi_threshold: default_rfi_threshold(),
10139            min_invited_vendors: default_min_invited_vendors(),
10140            max_invited_vendors: default_max_invited_vendors(),
10141            response_rate: default_response_rate(),
10142            default_price_weight: default_price_weight(),
10143            default_quality_weight: default_rfx_quality_weight(),
10144            default_delivery_weight: default_rfx_delivery_weight(),
10145        }
10146    }
10147}
10148
10149fn default_rfi_threshold() -> f64 {
10150    100_000.0
10151}
10152fn default_min_invited_vendors() -> u32 {
10153    3
10154}
10155fn default_max_invited_vendors() -> u32 {
10156    8
10157}
10158fn default_response_rate() -> f64 {
10159    0.70
10160}
10161fn default_price_weight() -> f64 {
10162    0.40
10163}
10164fn default_rfx_quality_weight() -> f64 {
10165    0.35
10166}
10167fn default_rfx_delivery_weight() -> f64 {
10168    0.25
10169}
10170
10171/// Contract configuration.
10172#[derive(Debug, Clone, Serialize, Deserialize)]
10173pub struct ContractConfig {
10174    /// Minimum contract duration in months
10175    #[serde(default = "default_min_contract_months")]
10176    pub min_duration_months: u32,
10177    /// Maximum contract duration in months
10178    #[serde(default = "default_max_contract_months")]
10179    pub max_duration_months: u32,
10180    /// Auto-renewal rate
10181    #[serde(default = "default_auto_renewal_rate")]
10182    pub auto_renewal_rate: f64,
10183    /// Amendment rate (% of contracts with at least one amendment)
10184    #[serde(default = "default_amendment_rate")]
10185    pub amendment_rate: f64,
10186    /// Distribution of contract types
10187    #[serde(default)]
10188    pub type_distribution: ContractTypeDistribution,
10189}
10190
10191impl Default for ContractConfig {
10192    fn default() -> Self {
10193        Self {
10194            min_duration_months: default_min_contract_months(),
10195            max_duration_months: default_max_contract_months(),
10196            auto_renewal_rate: default_auto_renewal_rate(),
10197            amendment_rate: default_amendment_rate(),
10198            type_distribution: ContractTypeDistribution::default(),
10199        }
10200    }
10201}
10202
10203fn default_min_contract_months() -> u32 {
10204    12
10205}
10206fn default_max_contract_months() -> u32 {
10207    36
10208}
10209fn default_auto_renewal_rate() -> f64 {
10210    0.40
10211}
10212fn default_amendment_rate() -> f64 {
10213    0.20
10214}
10215
10216/// Distribution of contract types.
10217#[derive(Debug, Clone, Serialize, Deserialize)]
10218pub struct ContractTypeDistribution {
10219    /// Fixed price percentage
10220    #[serde(default = "default_fixed_price_pct")]
10221    pub fixed_price: f64,
10222    /// Blanket/framework percentage
10223    #[serde(default = "default_blanket_pct")]
10224    pub blanket: f64,
10225    /// Time and materials percentage
10226    #[serde(default = "default_time_materials_pct")]
10227    pub time_and_materials: f64,
10228    /// Service agreement percentage
10229    #[serde(default = "default_service_agreement_pct")]
10230    pub service_agreement: f64,
10231}
10232
10233impl Default for ContractTypeDistribution {
10234    fn default() -> Self {
10235        Self {
10236            fixed_price: default_fixed_price_pct(),
10237            blanket: default_blanket_pct(),
10238            time_and_materials: default_time_materials_pct(),
10239            service_agreement: default_service_agreement_pct(),
10240        }
10241    }
10242}
10243
10244fn default_fixed_price_pct() -> f64 {
10245    0.40
10246}
10247fn default_blanket_pct() -> f64 {
10248    0.30
10249}
10250fn default_time_materials_pct() -> f64 {
10251    0.15
10252}
10253fn default_service_agreement_pct() -> f64 {
10254    0.15
10255}
10256
10257/// Catalog configuration.
10258#[derive(Debug, Clone, Serialize, Deserialize)]
10259pub struct CatalogConfig {
10260    /// Percentage of catalog items marked as preferred
10261    #[serde(default = "default_preferred_vendor_flag_rate")]
10262    pub preferred_vendor_flag_rate: f64,
10263    /// Rate of materials with multiple sources in catalog
10264    #[serde(default = "default_multi_source_rate")]
10265    pub multi_source_rate: f64,
10266}
10267
10268impl Default for CatalogConfig {
10269    fn default() -> Self {
10270        Self {
10271            preferred_vendor_flag_rate: default_preferred_vendor_flag_rate(),
10272            multi_source_rate: default_multi_source_rate(),
10273        }
10274    }
10275}
10276
10277fn default_preferred_vendor_flag_rate() -> f64 {
10278    0.70
10279}
10280fn default_multi_source_rate() -> f64 {
10281    0.25
10282}
10283
10284/// Scorecard configuration.
10285#[derive(Debug, Clone, Serialize, Deserialize)]
10286pub struct ScorecardConfig {
10287    /// Scorecard review frequency (quarterly, monthly)
10288    #[serde(default = "default_scorecard_frequency")]
10289    pub frequency: String,
10290    /// On-time delivery weight in overall score
10291    #[serde(default = "default_otd_weight")]
10292    pub on_time_delivery_weight: f64,
10293    /// Quality weight in overall score
10294    #[serde(default = "default_quality_score_weight")]
10295    pub quality_weight: f64,
10296    /// Price competitiveness weight
10297    #[serde(default = "default_price_score_weight")]
10298    pub price_weight: f64,
10299    /// Responsiveness weight
10300    #[serde(default = "default_responsiveness_weight")]
10301    pub responsiveness_weight: f64,
10302    /// Grade A threshold (score >= this)
10303    #[serde(default = "default_grade_a_threshold")]
10304    pub grade_a_threshold: f64,
10305    /// Grade B threshold
10306    #[serde(default = "default_grade_b_threshold")]
10307    pub grade_b_threshold: f64,
10308    /// Grade C threshold
10309    #[serde(default = "default_grade_c_threshold")]
10310    pub grade_c_threshold: f64,
10311}
10312
10313impl Default for ScorecardConfig {
10314    fn default() -> Self {
10315        Self {
10316            frequency: default_scorecard_frequency(),
10317            on_time_delivery_weight: default_otd_weight(),
10318            quality_weight: default_quality_score_weight(),
10319            price_weight: default_price_score_weight(),
10320            responsiveness_weight: default_responsiveness_weight(),
10321            grade_a_threshold: default_grade_a_threshold(),
10322            grade_b_threshold: default_grade_b_threshold(),
10323            grade_c_threshold: default_grade_c_threshold(),
10324        }
10325    }
10326}
10327
10328fn default_scorecard_frequency() -> String {
10329    "quarterly".to_string()
10330}
10331fn default_otd_weight() -> f64 {
10332    0.30
10333}
10334fn default_quality_score_weight() -> f64 {
10335    0.30
10336}
10337fn default_price_score_weight() -> f64 {
10338    0.25
10339}
10340fn default_responsiveness_weight() -> f64 {
10341    0.15
10342}
10343fn default_grade_a_threshold() -> f64 {
10344    90.0
10345}
10346fn default_grade_b_threshold() -> f64 {
10347    75.0
10348}
10349fn default_grade_c_threshold() -> f64 {
10350    60.0
10351}
10352
10353/// P2P integration settings for contract enforcement.
10354#[derive(Debug, Clone, Serialize, Deserialize)]
10355pub struct P2PIntegrationConfig {
10356    /// Rate of off-contract (maverick) purchases
10357    #[serde(default = "default_off_contract_rate")]
10358    pub off_contract_rate: f64,
10359    /// Price tolerance for contract price validation
10360    #[serde(default = "default_price_tolerance")]
10361    pub price_tolerance: f64,
10362    /// Whether to enforce catalog ordering
10363    #[serde(default)]
10364    pub catalog_enforcement: bool,
10365}
10366
10367impl Default for P2PIntegrationConfig {
10368    fn default() -> Self {
10369        Self {
10370            off_contract_rate: default_off_contract_rate(),
10371            price_tolerance: default_price_tolerance(),
10372            catalog_enforcement: false,
10373        }
10374    }
10375}
10376
10377fn default_off_contract_rate() -> f64 {
10378    0.15
10379}
10380fn default_price_tolerance() -> f64 {
10381    0.02
10382}
10383
10384// ----- Financial Reporting -----
10385
10386/// Financial reporting configuration.
10387#[derive(Debug, Clone, Serialize, Deserialize)]
10388pub struct FinancialReportingConfig {
10389    /// Enable financial reporting generation
10390    #[serde(default)]
10391    pub enabled: bool,
10392    /// Generate balance sheet
10393    #[serde(default = "default_true")]
10394    pub generate_balance_sheet: bool,
10395    /// Generate income statement
10396    #[serde(default = "default_true")]
10397    pub generate_income_statement: bool,
10398    /// Generate cash flow statement
10399    #[serde(default = "default_true")]
10400    pub generate_cash_flow: bool,
10401    /// Generate changes in equity statement
10402    #[serde(default = "default_true")]
10403    pub generate_changes_in_equity: bool,
10404    /// Number of comparative periods
10405    #[serde(default = "default_comparative_periods")]
10406    pub comparative_periods: u32,
10407    /// Management KPIs configuration
10408    #[serde(default)]
10409    pub management_kpis: ManagementKpisConfig,
10410    /// Budget configuration
10411    #[serde(default)]
10412    pub budgets: BudgetConfig,
10413}
10414
10415impl Default for FinancialReportingConfig {
10416    fn default() -> Self {
10417        Self {
10418            enabled: false,
10419            generate_balance_sheet: true,
10420            generate_income_statement: true,
10421            generate_cash_flow: true,
10422            generate_changes_in_equity: true,
10423            comparative_periods: default_comparative_periods(),
10424            management_kpis: ManagementKpisConfig::default(),
10425            budgets: BudgetConfig::default(),
10426        }
10427    }
10428}
10429
10430fn default_comparative_periods() -> u32 {
10431    1
10432}
10433
10434/// Management KPIs configuration.
10435#[derive(Debug, Clone, Default, Serialize, Deserialize)]
10436pub struct ManagementKpisConfig {
10437    /// Enable KPI generation
10438    #[serde(default)]
10439    pub enabled: bool,
10440    /// KPI calculation frequency (monthly, quarterly)
10441    #[serde(default = "default_kpi_frequency")]
10442    pub frequency: String,
10443}
10444
10445fn default_kpi_frequency() -> String {
10446    "monthly".to_string()
10447}
10448
10449/// Budget configuration.
10450#[derive(Debug, Clone, Serialize, Deserialize)]
10451pub struct BudgetConfig {
10452    /// Enable budget generation
10453    #[serde(default)]
10454    pub enabled: bool,
10455    /// Expected revenue growth rate for budgeting
10456    #[serde(default = "default_revenue_growth_rate")]
10457    pub revenue_growth_rate: f64,
10458    /// Expected expense inflation rate
10459    #[serde(default = "default_expense_inflation_rate")]
10460    pub expense_inflation_rate: f64,
10461    /// Random noise to add to budget vs actual
10462    #[serde(default = "default_variance_noise")]
10463    pub variance_noise: f64,
10464}
10465
10466impl Default for BudgetConfig {
10467    fn default() -> Self {
10468        Self {
10469            enabled: false,
10470            revenue_growth_rate: default_revenue_growth_rate(),
10471            expense_inflation_rate: default_expense_inflation_rate(),
10472            variance_noise: default_variance_noise(),
10473        }
10474    }
10475}
10476
10477fn default_revenue_growth_rate() -> f64 {
10478    0.05
10479}
10480fn default_expense_inflation_rate() -> f64 {
10481    0.03
10482}
10483fn default_variance_noise() -> f64 {
10484    0.10
10485}
10486
10487// ----- HR Configuration -----
10488
10489/// HR (Hire-to-Retire) process configuration.
10490#[derive(Debug, Clone, Default, Serialize, Deserialize)]
10491pub struct HrConfig {
10492    /// Enable HR generation
10493    #[serde(default)]
10494    pub enabled: bool,
10495    /// Payroll configuration
10496    #[serde(default)]
10497    pub payroll: PayrollConfig,
10498    /// Time and attendance configuration
10499    #[serde(default)]
10500    pub time_attendance: TimeAttendanceConfig,
10501    /// Expense management configuration
10502    #[serde(default)]
10503    pub expenses: ExpenseConfig,
10504}
10505
10506/// Payroll configuration.
10507#[derive(Debug, Clone, Serialize, Deserialize)]
10508pub struct PayrollConfig {
10509    /// Enable payroll generation
10510    #[serde(default = "default_true")]
10511    pub enabled: bool,
10512    /// Pay frequency (monthly, biweekly, weekly)
10513    #[serde(default = "default_pay_frequency")]
10514    pub pay_frequency: String,
10515    /// Salary ranges by job level
10516    #[serde(default)]
10517    pub salary_ranges: PayrollSalaryRanges,
10518    /// Effective tax rates
10519    #[serde(default)]
10520    pub tax_rates: PayrollTaxRates,
10521    /// Benefits enrollment rate
10522    #[serde(default = "default_benefits_enrollment_rate")]
10523    pub benefits_enrollment_rate: f64,
10524    /// Retirement plan participation rate
10525    #[serde(default = "default_retirement_participation_rate")]
10526    pub retirement_participation_rate: f64,
10527}
10528
10529impl Default for PayrollConfig {
10530    fn default() -> Self {
10531        Self {
10532            enabled: true,
10533            pay_frequency: default_pay_frequency(),
10534            salary_ranges: PayrollSalaryRanges::default(),
10535            tax_rates: PayrollTaxRates::default(),
10536            benefits_enrollment_rate: default_benefits_enrollment_rate(),
10537            retirement_participation_rate: default_retirement_participation_rate(),
10538        }
10539    }
10540}
10541
10542fn default_pay_frequency() -> String {
10543    "monthly".to_string()
10544}
10545fn default_benefits_enrollment_rate() -> f64 {
10546    0.60
10547}
10548fn default_retirement_participation_rate() -> f64 {
10549    0.45
10550}
10551
10552/// Salary ranges by job level.
10553#[derive(Debug, Clone, Serialize, Deserialize)]
10554pub struct PayrollSalaryRanges {
10555    /// Staff level min/max
10556    #[serde(default = "default_staff_min")]
10557    pub staff_min: f64,
10558    #[serde(default = "default_staff_max")]
10559    pub staff_max: f64,
10560    /// Manager level min/max
10561    #[serde(default = "default_manager_min")]
10562    pub manager_min: f64,
10563    #[serde(default = "default_manager_max")]
10564    pub manager_max: f64,
10565    /// Director level min/max
10566    #[serde(default = "default_director_min")]
10567    pub director_min: f64,
10568    #[serde(default = "default_director_max")]
10569    pub director_max: f64,
10570    /// Executive level min/max
10571    #[serde(default = "default_executive_min")]
10572    pub executive_min: f64,
10573    #[serde(default = "default_executive_max")]
10574    pub executive_max: f64,
10575}
10576
10577impl Default for PayrollSalaryRanges {
10578    fn default() -> Self {
10579        Self {
10580            staff_min: default_staff_min(),
10581            staff_max: default_staff_max(),
10582            manager_min: default_manager_min(),
10583            manager_max: default_manager_max(),
10584            director_min: default_director_min(),
10585            director_max: default_director_max(),
10586            executive_min: default_executive_min(),
10587            executive_max: default_executive_max(),
10588        }
10589    }
10590}
10591
10592fn default_staff_min() -> f64 {
10593    50_000.0
10594}
10595fn default_staff_max() -> f64 {
10596    70_000.0
10597}
10598fn default_manager_min() -> f64 {
10599    80_000.0
10600}
10601fn default_manager_max() -> f64 {
10602    120_000.0
10603}
10604fn default_director_min() -> f64 {
10605    120_000.0
10606}
10607fn default_director_max() -> f64 {
10608    180_000.0
10609}
10610fn default_executive_min() -> f64 {
10611    180_000.0
10612}
10613fn default_executive_max() -> f64 {
10614    350_000.0
10615}
10616
10617/// Effective tax rates for payroll.
10618#[derive(Debug, Clone, Serialize, Deserialize)]
10619pub struct PayrollTaxRates {
10620    /// Federal effective tax rate
10621    #[serde(default = "default_federal_rate")]
10622    pub federal_effective: f64,
10623    /// State effective tax rate
10624    #[serde(default = "default_state_rate")]
10625    pub state_effective: f64,
10626    /// FICA/social security rate
10627    #[serde(default = "default_fica_rate")]
10628    pub fica: f64,
10629}
10630
10631impl Default for PayrollTaxRates {
10632    fn default() -> Self {
10633        Self {
10634            federal_effective: default_federal_rate(),
10635            state_effective: default_state_rate(),
10636            fica: default_fica_rate(),
10637        }
10638    }
10639}
10640
10641fn default_federal_rate() -> f64 {
10642    0.22
10643}
10644fn default_state_rate() -> f64 {
10645    0.05
10646}
10647fn default_fica_rate() -> f64 {
10648    0.0765
10649}
10650
10651/// Time and attendance configuration.
10652#[derive(Debug, Clone, Serialize, Deserialize)]
10653pub struct TimeAttendanceConfig {
10654    /// Enable time tracking
10655    #[serde(default = "default_true")]
10656    pub enabled: bool,
10657    /// Overtime rate (% of employees with overtime in a period)
10658    #[serde(default = "default_overtime_rate")]
10659    pub overtime_rate: f64,
10660}
10661
10662impl Default for TimeAttendanceConfig {
10663    fn default() -> Self {
10664        Self {
10665            enabled: true,
10666            overtime_rate: default_overtime_rate(),
10667        }
10668    }
10669}
10670
10671fn default_overtime_rate() -> f64 {
10672    0.10
10673}
10674
10675/// Expense management configuration.
10676#[derive(Debug, Clone, Serialize, Deserialize)]
10677pub struct ExpenseConfig {
10678    /// Enable expense report generation
10679    #[serde(default = "default_true")]
10680    pub enabled: bool,
10681    /// Rate of employees submitting expenses per month
10682    #[serde(default = "default_expense_submission_rate")]
10683    pub submission_rate: f64,
10684    /// Rate of policy violations
10685    #[serde(default = "default_policy_violation_rate")]
10686    pub policy_violation_rate: f64,
10687}
10688
10689impl Default for ExpenseConfig {
10690    fn default() -> Self {
10691        Self {
10692            enabled: true,
10693            submission_rate: default_expense_submission_rate(),
10694            policy_violation_rate: default_policy_violation_rate(),
10695        }
10696    }
10697}
10698
10699fn default_expense_submission_rate() -> f64 {
10700    0.30
10701}
10702fn default_policy_violation_rate() -> f64 {
10703    0.08
10704}
10705
10706// ----- Manufacturing Configuration -----
10707
10708/// Manufacturing process configuration (production orders, WIP, routing).
10709#[derive(Debug, Clone, Default, Serialize, Deserialize)]
10710pub struct ManufacturingProcessConfig {
10711    /// Enable manufacturing generation
10712    #[serde(default)]
10713    pub enabled: bool,
10714    /// Production order configuration
10715    #[serde(default)]
10716    pub production_orders: ProductionOrderConfig,
10717    /// Costing configuration
10718    #[serde(default)]
10719    pub costing: ManufacturingCostingConfig,
10720    /// Routing configuration
10721    #[serde(default)]
10722    pub routing: RoutingConfig,
10723}
10724
10725/// Production order configuration.
10726#[derive(Debug, Clone, Serialize, Deserialize)]
10727pub struct ProductionOrderConfig {
10728    /// Orders per month
10729    #[serde(default = "default_prod_orders_per_month")]
10730    pub orders_per_month: u32,
10731    /// Average batch size
10732    #[serde(default = "default_prod_avg_batch_size")]
10733    pub avg_batch_size: u32,
10734    /// Yield rate
10735    #[serde(default = "default_prod_yield_rate")]
10736    pub yield_rate: f64,
10737    /// Make-to-order rate (vs make-to-stock)
10738    #[serde(default = "default_prod_make_to_order_rate")]
10739    pub make_to_order_rate: f64,
10740    /// Rework rate
10741    #[serde(default = "default_prod_rework_rate")]
10742    pub rework_rate: f64,
10743}
10744
10745impl Default for ProductionOrderConfig {
10746    fn default() -> Self {
10747        Self {
10748            orders_per_month: default_prod_orders_per_month(),
10749            avg_batch_size: default_prod_avg_batch_size(),
10750            yield_rate: default_prod_yield_rate(),
10751            make_to_order_rate: default_prod_make_to_order_rate(),
10752            rework_rate: default_prod_rework_rate(),
10753        }
10754    }
10755}
10756
10757fn default_prod_orders_per_month() -> u32 {
10758    50
10759}
10760fn default_prod_avg_batch_size() -> u32 {
10761    100
10762}
10763fn default_prod_yield_rate() -> f64 {
10764    0.97
10765}
10766fn default_prod_make_to_order_rate() -> f64 {
10767    0.20
10768}
10769fn default_prod_rework_rate() -> f64 {
10770    0.03
10771}
10772
10773/// Manufacturing costing configuration.
10774#[derive(Debug, Clone, Serialize, Deserialize)]
10775pub struct ManufacturingCostingConfig {
10776    /// Labor rate per hour
10777    #[serde(default = "default_labor_rate")]
10778    pub labor_rate_per_hour: f64,
10779    /// Overhead application rate (multiplier on direct labor)
10780    #[serde(default = "default_overhead_rate")]
10781    pub overhead_rate: f64,
10782    /// Standard cost update frequency
10783    #[serde(default = "default_cost_update_frequency")]
10784    pub standard_cost_update_frequency: String,
10785}
10786
10787impl Default for ManufacturingCostingConfig {
10788    fn default() -> Self {
10789        Self {
10790            labor_rate_per_hour: default_labor_rate(),
10791            overhead_rate: default_overhead_rate(),
10792            standard_cost_update_frequency: default_cost_update_frequency(),
10793        }
10794    }
10795}
10796
10797fn default_labor_rate() -> f64 {
10798    35.0
10799}
10800fn default_overhead_rate() -> f64 {
10801    1.50
10802}
10803fn default_cost_update_frequency() -> String {
10804    "quarterly".to_string()
10805}
10806
10807/// Routing configuration for production operations.
10808#[derive(Debug, Clone, Serialize, Deserialize)]
10809pub struct RoutingConfig {
10810    /// Average number of operations per routing
10811    #[serde(default = "default_avg_operations")]
10812    pub avg_operations: u32,
10813    /// Average setup time in hours
10814    #[serde(default = "default_setup_time")]
10815    pub setup_time_hours: f64,
10816    /// Run time variation coefficient
10817    #[serde(default = "default_run_time_variation")]
10818    pub run_time_variation: f64,
10819}
10820
10821impl Default for RoutingConfig {
10822    fn default() -> Self {
10823        Self {
10824            avg_operations: default_avg_operations(),
10825            setup_time_hours: default_setup_time(),
10826            run_time_variation: default_run_time_variation(),
10827        }
10828    }
10829}
10830
10831fn default_avg_operations() -> u32 {
10832    4
10833}
10834fn default_setup_time() -> f64 {
10835    1.5
10836}
10837fn default_run_time_variation() -> f64 {
10838    0.15
10839}
10840
10841// ----- Sales Quote Configuration -----
10842
10843/// Sales quote (quote-to-order) pipeline configuration.
10844#[derive(Debug, Clone, Serialize, Deserialize)]
10845pub struct SalesQuoteConfig {
10846    /// Enable sales quote generation
10847    #[serde(default)]
10848    pub enabled: bool,
10849    /// Quotes per month
10850    #[serde(default = "default_quotes_per_month")]
10851    pub quotes_per_month: u32,
10852    /// Win rate (fraction of quotes that convert to orders)
10853    #[serde(default = "default_quote_win_rate")]
10854    pub win_rate: f64,
10855    /// Average quote validity in days
10856    #[serde(default = "default_quote_validity_days")]
10857    pub validity_days: u32,
10858}
10859
10860impl Default for SalesQuoteConfig {
10861    fn default() -> Self {
10862        Self {
10863            enabled: false,
10864            quotes_per_month: default_quotes_per_month(),
10865            win_rate: default_quote_win_rate(),
10866            validity_days: default_quote_validity_days(),
10867        }
10868    }
10869}
10870
10871fn default_quotes_per_month() -> u32 {
10872    30
10873}
10874fn default_quote_win_rate() -> f64 {
10875    0.35
10876}
10877fn default_quote_validity_days() -> u32 {
10878    30
10879}
10880
10881// =============================================================================
10882// Tax Accounting Configuration
10883// =============================================================================
10884
10885/// Tax accounting configuration.
10886///
10887/// Controls generation of tax-related data including VAT/GST, sales tax,
10888/// withholding tax, tax provisions, and payroll tax across multiple jurisdictions.
10889#[derive(Debug, Clone, Serialize, Deserialize)]
10890pub struct TaxConfig {
10891    /// Whether tax generation is enabled.
10892    #[serde(default)]
10893    pub enabled: bool,
10894    /// Tax jurisdiction configuration.
10895    #[serde(default)]
10896    pub jurisdictions: TaxJurisdictionConfig,
10897    /// VAT/GST configuration.
10898    #[serde(default)]
10899    pub vat_gst: VatGstConfig,
10900    /// Sales tax configuration.
10901    #[serde(default)]
10902    pub sales_tax: SalesTaxConfig,
10903    /// Withholding tax configuration.
10904    #[serde(default)]
10905    pub withholding: WithholdingTaxSchemaConfig,
10906    /// Tax provision configuration.
10907    #[serde(default)]
10908    pub provisions: TaxProvisionSchemaConfig,
10909    /// Payroll tax configuration.
10910    #[serde(default)]
10911    pub payroll_tax: PayrollTaxSchemaConfig,
10912    /// Anomaly injection rate for tax data (0.0 to 1.0).
10913    #[serde(default = "default_tax_anomaly_rate")]
10914    pub anomaly_rate: f64,
10915}
10916
10917fn default_tax_anomaly_rate() -> f64 {
10918    0.03
10919}
10920
10921impl Default for TaxConfig {
10922    fn default() -> Self {
10923        Self {
10924            enabled: false,
10925            jurisdictions: TaxJurisdictionConfig::default(),
10926            vat_gst: VatGstConfig::default(),
10927            sales_tax: SalesTaxConfig::default(),
10928            withholding: WithholdingTaxSchemaConfig::default(),
10929            provisions: TaxProvisionSchemaConfig::default(),
10930            payroll_tax: PayrollTaxSchemaConfig::default(),
10931            anomaly_rate: default_tax_anomaly_rate(),
10932        }
10933    }
10934}
10935
10936/// Tax jurisdiction configuration.
10937///
10938/// Specifies which countries and subnational jurisdictions to include
10939/// when generating tax data.
10940#[derive(Debug, Clone, Default, Serialize, Deserialize)]
10941pub struct TaxJurisdictionConfig {
10942    /// List of country codes to include (e.g., ["US", "DE", "GB"]).
10943    #[serde(default)]
10944    pub countries: Vec<String>,
10945    /// Whether to include subnational jurisdictions (e.g., US states, Canadian provinces).
10946    #[serde(default)]
10947    pub include_subnational: bool,
10948}
10949
10950/// VAT/GST configuration.
10951///
10952/// Controls generation of Value Added Tax / Goods and Services Tax data,
10953/// including standard and reduced rates, exempt categories, and reverse charge.
10954#[derive(Debug, Clone, Serialize, Deserialize)]
10955pub struct VatGstConfig {
10956    /// Whether VAT/GST generation is enabled.
10957    #[serde(default)]
10958    pub enabled: bool,
10959    /// Standard VAT/GST rates by country code (e.g., {"DE": 0.19, "GB": 0.20}).
10960    #[serde(default)]
10961    pub standard_rates: std::collections::HashMap<String, f64>,
10962    /// Reduced VAT/GST rates by country code (e.g., {"DE": 0.07, "GB": 0.05}).
10963    #[serde(default)]
10964    pub reduced_rates: std::collections::HashMap<String, f64>,
10965    /// Categories exempt from VAT/GST (e.g., ["financial_services", "healthcare"]).
10966    #[serde(default)]
10967    pub exempt_categories: Vec<String>,
10968    /// Whether to apply reverse charge mechanism for cross-border B2B transactions.
10969    #[serde(default = "default_true")]
10970    pub reverse_charge: bool,
10971}
10972
10973impl Default for VatGstConfig {
10974    fn default() -> Self {
10975        Self {
10976            enabled: false,
10977            standard_rates: std::collections::HashMap::new(),
10978            reduced_rates: std::collections::HashMap::new(),
10979            exempt_categories: Vec::new(),
10980            reverse_charge: true,
10981        }
10982    }
10983}
10984
10985/// Sales tax configuration.
10986///
10987/// Controls generation of US-style sales tax data including nexus determination.
10988#[derive(Debug, Clone, Default, Serialize, Deserialize)]
10989pub struct SalesTaxConfig {
10990    /// Whether sales tax generation is enabled.
10991    #[serde(default)]
10992    pub enabled: bool,
10993    /// US states where the company has nexus (e.g., ["CA", "NY", "TX"]).
10994    #[serde(default)]
10995    pub nexus_states: Vec<String>,
10996}
10997
10998/// Withholding tax configuration.
10999///
11000/// Controls generation of withholding tax data for cross-border payments,
11001/// including treaty network and rate overrides.
11002#[derive(Debug, Clone, Serialize, Deserialize)]
11003pub struct WithholdingTaxSchemaConfig {
11004    /// Whether withholding tax generation is enabled.
11005    #[serde(default)]
11006    pub enabled: bool,
11007    /// Whether to simulate a treaty network with reduced rates.
11008    #[serde(default = "default_true")]
11009    pub treaty_network: bool,
11010    /// Default withholding tax rate for non-treaty countries (0.0 to 1.0).
11011    #[serde(default = "default_withholding_rate")]
11012    pub default_rate: f64,
11013    /// Reduced withholding tax rate for treaty countries (0.0 to 1.0).
11014    #[serde(default = "default_treaty_reduced_rate")]
11015    pub treaty_reduced_rate: f64,
11016}
11017
11018fn default_withholding_rate() -> f64 {
11019    0.30
11020}
11021
11022fn default_treaty_reduced_rate() -> f64 {
11023    0.15
11024}
11025
11026impl Default for WithholdingTaxSchemaConfig {
11027    fn default() -> Self {
11028        Self {
11029            enabled: false,
11030            treaty_network: true,
11031            default_rate: default_withholding_rate(),
11032            treaty_reduced_rate: default_treaty_reduced_rate(),
11033        }
11034    }
11035}
11036
11037/// Tax provision configuration.
11038///
11039/// Controls generation of tax provision data including statutory rates
11040/// and uncertain tax positions (ASC 740 / IAS 12).
11041#[derive(Debug, Clone, Serialize, Deserialize)]
11042pub struct TaxProvisionSchemaConfig {
11043    /// Whether tax provision generation is enabled.
11044    /// Defaults to true when tax is enabled, as provisions are typically required.
11045    #[serde(default = "default_true")]
11046    pub enabled: bool,
11047    /// Statutory corporate tax rate (0.0 to 1.0).
11048    #[serde(default = "default_statutory_rate")]
11049    pub statutory_rate: f64,
11050    /// Whether to generate uncertain tax positions (FIN 48 / IFRIC 23).
11051    #[serde(default = "default_true")]
11052    pub uncertain_positions: bool,
11053}
11054
11055fn default_statutory_rate() -> f64 {
11056    0.21
11057}
11058
11059impl Default for TaxProvisionSchemaConfig {
11060    fn default() -> Self {
11061        Self {
11062            enabled: true,
11063            statutory_rate: default_statutory_rate(),
11064            uncertain_positions: true,
11065        }
11066    }
11067}
11068
11069/// Payroll tax configuration.
11070///
11071/// Controls generation of payroll tax data (employer/employee contributions,
11072/// social security, Medicare, etc.).
11073#[derive(Debug, Clone, Default, Serialize, Deserialize)]
11074pub struct PayrollTaxSchemaConfig {
11075    /// Whether payroll tax generation is enabled.
11076    #[serde(default)]
11077    pub enabled: bool,
11078}
11079
11080// ---------------------------------------------------------------------------
11081// Treasury & Cash Management Configuration
11082// ---------------------------------------------------------------------------
11083
11084/// Treasury and cash management configuration.
11085///
11086/// Controls generation of cash positions, forecasts, pooling, hedging
11087/// instruments (ASC 815 / IFRS 9), debt instruments with covenants,
11088/// bank guarantees, and intercompany netting runs.
11089#[derive(Debug, Clone, Serialize, Deserialize)]
11090pub struct TreasuryConfig {
11091    /// Whether treasury generation is enabled.
11092    #[serde(default)]
11093    pub enabled: bool,
11094    /// Cash positioning configuration.
11095    #[serde(default)]
11096    pub cash_positioning: CashPositioningConfig,
11097    /// Cash forecasting configuration.
11098    #[serde(default)]
11099    pub cash_forecasting: CashForecastingConfig,
11100    /// Cash pooling configuration.
11101    #[serde(default)]
11102    pub cash_pooling: CashPoolingConfig,
11103    /// Hedging configuration (FX forwards, IR swaps, etc.).
11104    #[serde(default)]
11105    pub hedging: HedgingSchemaConfig,
11106    /// Debt instrument and covenant configuration.
11107    #[serde(default)]
11108    pub debt: DebtSchemaConfig,
11109    /// Intercompany netting configuration.
11110    #[serde(default)]
11111    pub netting: NettingSchemaConfig,
11112    /// Bank guarantee / letter of credit configuration.
11113    #[serde(default)]
11114    pub bank_guarantees: BankGuaranteeSchemaConfig,
11115    /// Anomaly injection rate for treasury data (0.0 to 1.0).
11116    #[serde(default = "default_treasury_anomaly_rate")]
11117    pub anomaly_rate: f64,
11118}
11119
11120fn default_treasury_anomaly_rate() -> f64 {
11121    0.02
11122}
11123
11124impl Default for TreasuryConfig {
11125    fn default() -> Self {
11126        Self {
11127            enabled: false,
11128            cash_positioning: CashPositioningConfig::default(),
11129            cash_forecasting: CashForecastingConfig::default(),
11130            cash_pooling: CashPoolingConfig::default(),
11131            hedging: HedgingSchemaConfig::default(),
11132            debt: DebtSchemaConfig::default(),
11133            netting: NettingSchemaConfig::default(),
11134            bank_guarantees: BankGuaranteeSchemaConfig::default(),
11135            anomaly_rate: default_treasury_anomaly_rate(),
11136        }
11137    }
11138}
11139
11140/// Cash positioning configuration.
11141///
11142/// Controls daily cash position generation per entity/bank account.
11143#[derive(Debug, Clone, Serialize, Deserialize)]
11144pub struct CashPositioningConfig {
11145    /// Whether cash positioning is enabled.
11146    #[serde(default = "default_true")]
11147    pub enabled: bool,
11148    /// Position generation frequency.
11149    #[serde(default = "default_cash_frequency")]
11150    pub frequency: String,
11151    /// Minimum cash balance policy threshold.
11152    #[serde(default = "default_minimum_balance_policy")]
11153    pub minimum_balance_policy: f64,
11154}
11155
11156fn default_cash_frequency() -> String {
11157    "daily".to_string()
11158}
11159
11160fn default_minimum_balance_policy() -> f64 {
11161    100_000.0
11162}
11163
11164impl Default for CashPositioningConfig {
11165    fn default() -> Self {
11166        Self {
11167            enabled: true,
11168            frequency: default_cash_frequency(),
11169            minimum_balance_policy: default_minimum_balance_policy(),
11170        }
11171    }
11172}
11173
11174/// Cash forecasting configuration.
11175///
11176/// Controls forward-looking cash forecast generation with probability-weighted items.
11177#[derive(Debug, Clone, Serialize, Deserialize)]
11178pub struct CashForecastingConfig {
11179    /// Whether cash forecasting is enabled.
11180    #[serde(default = "default_true")]
11181    pub enabled: bool,
11182    /// Number of days to forecast into the future.
11183    #[serde(default = "default_horizon_days")]
11184    pub horizon_days: u32,
11185    /// AR collection probability curve type ("aging" or "flat").
11186    #[serde(default = "default_ar_probability_curve")]
11187    pub ar_collection_probability_curve: String,
11188    /// Confidence interval for the forecast (0.0 to 1.0).
11189    #[serde(default = "default_confidence_interval")]
11190    pub confidence_interval: f64,
11191}
11192
11193fn default_horizon_days() -> u32 {
11194    90
11195}
11196
11197fn default_ar_probability_curve() -> String {
11198    "aging".to_string()
11199}
11200
11201fn default_confidence_interval() -> f64 {
11202    0.90
11203}
11204
11205impl Default for CashForecastingConfig {
11206    fn default() -> Self {
11207        Self {
11208            enabled: true,
11209            horizon_days: default_horizon_days(),
11210            ar_collection_probability_curve: default_ar_probability_curve(),
11211            confidence_interval: default_confidence_interval(),
11212        }
11213    }
11214}
11215
11216/// Cash pooling configuration.
11217///
11218/// Controls cash pool structure generation (physical, notional, zero-balancing).
11219#[derive(Debug, Clone, Serialize, Deserialize)]
11220pub struct CashPoolingConfig {
11221    /// Whether cash pooling is enabled.
11222    #[serde(default)]
11223    pub enabled: bool,
11224    /// Pool type: "physical_pooling", "notional_pooling", or "zero_balancing".
11225    #[serde(default = "default_pool_type")]
11226    pub pool_type: String,
11227    /// Time of day when sweeps occur (HH:MM format).
11228    #[serde(default = "default_sweep_time")]
11229    pub sweep_time: String,
11230}
11231
11232fn default_pool_type() -> String {
11233    "zero_balancing".to_string()
11234}
11235
11236fn default_sweep_time() -> String {
11237    "16:00".to_string()
11238}
11239
11240impl Default for CashPoolingConfig {
11241    fn default() -> Self {
11242        Self {
11243            enabled: false,
11244            pool_type: default_pool_type(),
11245            sweep_time: default_sweep_time(),
11246        }
11247    }
11248}
11249
11250/// Hedging configuration.
11251///
11252/// Controls generation of hedging instruments and hedge relationship designations
11253/// under ASC 815 / IFRS 9.
11254#[derive(Debug, Clone, Serialize, Deserialize)]
11255pub struct HedgingSchemaConfig {
11256    /// Whether hedging generation is enabled.
11257    #[serde(default)]
11258    pub enabled: bool,
11259    /// Target hedge ratio (0.0 to 1.0). Proportion of FX exposure to hedge.
11260    #[serde(default = "default_hedge_ratio")]
11261    pub hedge_ratio: f64,
11262    /// Types of instruments to generate (e.g., ["fx_forward", "interest_rate_swap"]).
11263    #[serde(default = "default_hedge_instruments")]
11264    pub instruments: Vec<String>,
11265    /// Whether to designate formal hedge accounting relationships.
11266    #[serde(default = "default_true")]
11267    pub hedge_accounting: bool,
11268    /// Effectiveness testing method: "dollar_offset", "regression", or "critical_terms".
11269    #[serde(default = "default_effectiveness_method")]
11270    pub effectiveness_method: String,
11271}
11272
11273fn default_hedge_ratio() -> f64 {
11274    0.75
11275}
11276
11277fn default_hedge_instruments() -> Vec<String> {
11278    vec!["fx_forward".to_string(), "interest_rate_swap".to_string()]
11279}
11280
11281fn default_effectiveness_method() -> String {
11282    "regression".to_string()
11283}
11284
11285impl Default for HedgingSchemaConfig {
11286    fn default() -> Self {
11287        Self {
11288            enabled: false,
11289            hedge_ratio: default_hedge_ratio(),
11290            instruments: default_hedge_instruments(),
11291            hedge_accounting: true,
11292            effectiveness_method: default_effectiveness_method(),
11293        }
11294    }
11295}
11296
11297/// Debt instrument configuration.
11298///
11299/// Controls generation of debt instruments (term loans, revolving credit, bonds)
11300/// with amortization schedules and financial covenants.
11301#[derive(Debug, Clone, Default, Serialize, Deserialize)]
11302pub struct DebtSchemaConfig {
11303    /// Whether debt instrument generation is enabled.
11304    #[serde(default)]
11305    pub enabled: bool,
11306    /// Debt instrument definitions.
11307    #[serde(default)]
11308    pub instruments: Vec<DebtInstrumentDef>,
11309    /// Covenant definitions.
11310    #[serde(default)]
11311    pub covenants: Vec<CovenantDef>,
11312}
11313
11314/// Definition of a debt instrument in configuration.
11315#[derive(Debug, Clone, Serialize, Deserialize)]
11316pub struct DebtInstrumentDef {
11317    /// Instrument type: "term_loan", "revolving_credit", "bond", "commercial_paper", "bridge_loan".
11318    #[serde(rename = "type")]
11319    pub instrument_type: String,
11320    /// Principal amount (for term loans, bonds).
11321    #[serde(default)]
11322    pub principal: Option<f64>,
11323    /// Interest rate (annual, as decimal fraction).
11324    #[serde(default)]
11325    pub rate: Option<f64>,
11326    /// Maturity in months.
11327    #[serde(default)]
11328    pub maturity_months: Option<u32>,
11329    /// Facility limit (for revolving credit).
11330    #[serde(default)]
11331    pub facility: Option<f64>,
11332}
11333
11334/// Definition of a debt covenant in configuration.
11335#[derive(Debug, Clone, Serialize, Deserialize)]
11336pub struct CovenantDef {
11337    /// Covenant type: "debt_to_equity", "interest_coverage", "current_ratio",
11338    /// "net_worth", "debt_to_ebitda", "fixed_charge_coverage".
11339    #[serde(rename = "type")]
11340    pub covenant_type: String,
11341    /// Covenant threshold value.
11342    pub threshold: f64,
11343}
11344
11345/// Intercompany netting configuration.
11346///
11347/// Controls generation of multilateral netting runs.
11348#[derive(Debug, Clone, Serialize, Deserialize)]
11349pub struct NettingSchemaConfig {
11350    /// Whether netting generation is enabled.
11351    #[serde(default)]
11352    pub enabled: bool,
11353    /// Netting cycle: "daily", "weekly", or "monthly".
11354    #[serde(default = "default_netting_cycle")]
11355    pub cycle: String,
11356}
11357
11358fn default_netting_cycle() -> String {
11359    "monthly".to_string()
11360}
11361
11362impl Default for NettingSchemaConfig {
11363    fn default() -> Self {
11364        Self {
11365            enabled: false,
11366            cycle: default_netting_cycle(),
11367        }
11368    }
11369}
11370
11371/// Bank guarantee and letter of credit configuration.
11372///
11373/// Controls generation of bank guarantees, standby LCs, and performance bonds.
11374#[derive(Debug, Clone, Serialize, Deserialize)]
11375pub struct BankGuaranteeSchemaConfig {
11376    /// Whether bank guarantee generation is enabled.
11377    #[serde(default)]
11378    pub enabled: bool,
11379    /// Number of guarantees to generate.
11380    #[serde(default = "default_guarantee_count")]
11381    pub count: u32,
11382}
11383
11384fn default_guarantee_count() -> u32 {
11385    5
11386}
11387
11388impl Default for BankGuaranteeSchemaConfig {
11389    fn default() -> Self {
11390        Self {
11391            enabled: false,
11392            count: default_guarantee_count(),
11393        }
11394    }
11395}
11396
11397// ===========================================================================
11398// Project Accounting Configuration
11399// ===========================================================================
11400
11401/// Project accounting configuration.
11402///
11403/// Controls generation of project cost lines, revenue recognition,
11404/// milestones, change orders, retainage, and earned value metrics.
11405#[derive(Debug, Clone, Serialize, Deserialize)]
11406pub struct ProjectAccountingConfig {
11407    /// Whether project accounting is enabled.
11408    #[serde(default)]
11409    pub enabled: bool,
11410    /// Number of projects to generate.
11411    #[serde(default = "default_project_count")]
11412    pub project_count: u32,
11413    /// Distribution of project types (capital, internal, customer, r_and_d, maintenance, technology).
11414    #[serde(default)]
11415    pub project_types: ProjectTypeDistribution,
11416    /// WBS structure configuration.
11417    #[serde(default)]
11418    pub wbs: WbsSchemaConfig,
11419    /// Cost allocation rates (what % of source documents get project-tagged).
11420    #[serde(default)]
11421    pub cost_allocation: CostAllocationConfig,
11422    /// Revenue recognition configuration for project accounting.
11423    #[serde(default)]
11424    pub revenue_recognition: ProjectRevenueRecognitionConfig,
11425    /// Milestone configuration.
11426    #[serde(default)]
11427    pub milestones: MilestoneSchemaConfig,
11428    /// Change order configuration.
11429    #[serde(default)]
11430    pub change_orders: ChangeOrderSchemaConfig,
11431    /// Retainage configuration.
11432    #[serde(default)]
11433    pub retainage: RetainageSchemaConfig,
11434    /// Earned value management configuration.
11435    #[serde(default)]
11436    pub earned_value: EarnedValueSchemaConfig,
11437    /// Anomaly injection rate for project accounting data (0.0 to 1.0).
11438    #[serde(default = "default_project_anomaly_rate")]
11439    pub anomaly_rate: f64,
11440}
11441
11442fn default_project_count() -> u32 {
11443    10
11444}
11445
11446fn default_project_anomaly_rate() -> f64 {
11447    0.03
11448}
11449
11450impl Default for ProjectAccountingConfig {
11451    fn default() -> Self {
11452        Self {
11453            enabled: false,
11454            project_count: default_project_count(),
11455            project_types: ProjectTypeDistribution::default(),
11456            wbs: WbsSchemaConfig::default(),
11457            cost_allocation: CostAllocationConfig::default(),
11458            revenue_recognition: ProjectRevenueRecognitionConfig::default(),
11459            milestones: MilestoneSchemaConfig::default(),
11460            change_orders: ChangeOrderSchemaConfig::default(),
11461            retainage: RetainageSchemaConfig::default(),
11462            earned_value: EarnedValueSchemaConfig::default(),
11463            anomaly_rate: default_project_anomaly_rate(),
11464        }
11465    }
11466}
11467
11468/// Distribution of project types by weight.
11469#[derive(Debug, Clone, Serialize, Deserialize)]
11470pub struct ProjectTypeDistribution {
11471    /// Weight for capital projects (default 0.25).
11472    #[serde(default = "default_capital_weight")]
11473    pub capital: f64,
11474    /// Weight for internal projects (default 0.20).
11475    #[serde(default = "default_internal_weight")]
11476    pub internal: f64,
11477    /// Weight for customer projects (default 0.30).
11478    #[serde(default = "default_customer_weight")]
11479    pub customer: f64,
11480    /// Weight for R&D projects (default 0.10).
11481    #[serde(default = "default_rnd_weight")]
11482    pub r_and_d: f64,
11483    /// Weight for maintenance projects (default 0.10).
11484    #[serde(default = "default_maintenance_weight")]
11485    pub maintenance: f64,
11486    /// Weight for technology projects (default 0.05).
11487    #[serde(default = "default_technology_weight")]
11488    pub technology: f64,
11489}
11490
11491fn default_capital_weight() -> f64 {
11492    0.25
11493}
11494fn default_internal_weight() -> f64 {
11495    0.20
11496}
11497fn default_customer_weight() -> f64 {
11498    0.30
11499}
11500fn default_rnd_weight() -> f64 {
11501    0.10
11502}
11503fn default_maintenance_weight() -> f64 {
11504    0.10
11505}
11506fn default_technology_weight() -> f64 {
11507    0.05
11508}
11509
11510impl Default for ProjectTypeDistribution {
11511    fn default() -> Self {
11512        Self {
11513            capital: default_capital_weight(),
11514            internal: default_internal_weight(),
11515            customer: default_customer_weight(),
11516            r_and_d: default_rnd_weight(),
11517            maintenance: default_maintenance_weight(),
11518            technology: default_technology_weight(),
11519        }
11520    }
11521}
11522
11523/// WBS structure configuration.
11524#[derive(Debug, Clone, Serialize, Deserialize)]
11525pub struct WbsSchemaConfig {
11526    /// Maximum depth of WBS hierarchy (default 3).
11527    #[serde(default = "default_wbs_max_depth")]
11528    pub max_depth: u32,
11529    /// Minimum elements per level-1 WBS (default 2).
11530    #[serde(default = "default_wbs_min_elements")]
11531    pub min_elements_per_level: u32,
11532    /// Maximum elements per level-1 WBS (default 6).
11533    #[serde(default = "default_wbs_max_elements")]
11534    pub max_elements_per_level: u32,
11535}
11536
11537fn default_wbs_max_depth() -> u32 {
11538    3
11539}
11540fn default_wbs_min_elements() -> u32 {
11541    2
11542}
11543fn default_wbs_max_elements() -> u32 {
11544    6
11545}
11546
11547impl Default for WbsSchemaConfig {
11548    fn default() -> Self {
11549        Self {
11550            max_depth: default_wbs_max_depth(),
11551            min_elements_per_level: default_wbs_min_elements(),
11552            max_elements_per_level: default_wbs_max_elements(),
11553        }
11554    }
11555}
11556
11557/// Cost allocation rates — what fraction of each document type gets linked to a project.
11558#[derive(Debug, Clone, Serialize, Deserialize)]
11559pub struct CostAllocationConfig {
11560    /// Fraction of time entries assigned to projects (0.0 to 1.0).
11561    #[serde(default = "default_time_entry_rate")]
11562    pub time_entry_project_rate: f64,
11563    /// Fraction of expense reports assigned to projects (0.0 to 1.0).
11564    #[serde(default = "default_expense_rate")]
11565    pub expense_project_rate: f64,
11566    /// Fraction of purchase orders assigned to projects (0.0 to 1.0).
11567    #[serde(default = "default_po_rate")]
11568    pub purchase_order_project_rate: f64,
11569    /// Fraction of vendor invoices assigned to projects (0.0 to 1.0).
11570    #[serde(default = "default_vi_rate")]
11571    pub vendor_invoice_project_rate: f64,
11572}
11573
11574fn default_time_entry_rate() -> f64 {
11575    0.60
11576}
11577fn default_expense_rate() -> f64 {
11578    0.30
11579}
11580fn default_po_rate() -> f64 {
11581    0.40
11582}
11583fn default_vi_rate() -> f64 {
11584    0.35
11585}
11586
11587impl Default for CostAllocationConfig {
11588    fn default() -> Self {
11589        Self {
11590            time_entry_project_rate: default_time_entry_rate(),
11591            expense_project_rate: default_expense_rate(),
11592            purchase_order_project_rate: default_po_rate(),
11593            vendor_invoice_project_rate: default_vi_rate(),
11594        }
11595    }
11596}
11597
11598/// Revenue recognition configuration for project accounting.
11599#[derive(Debug, Clone, Serialize, Deserialize)]
11600pub struct ProjectRevenueRecognitionConfig {
11601    /// Whether revenue recognition is enabled for customer projects.
11602    #[serde(default = "default_true")]
11603    pub enabled: bool,
11604    /// Default method: "percentage_of_completion", "completed_contract", "milestone_based".
11605    #[serde(default = "default_revenue_method")]
11606    pub method: String,
11607    /// Default completion measure: "cost_to_cost", "labor_hours", "physical_completion".
11608    #[serde(default = "default_completion_measure")]
11609    pub completion_measure: String,
11610    /// Average contract value for customer projects.
11611    #[serde(default = "default_avg_contract_value")]
11612    pub avg_contract_value: f64,
11613}
11614
11615fn default_revenue_method() -> String {
11616    "percentage_of_completion".to_string()
11617}
11618fn default_completion_measure() -> String {
11619    "cost_to_cost".to_string()
11620}
11621fn default_avg_contract_value() -> f64 {
11622    500_000.0
11623}
11624
11625impl Default for ProjectRevenueRecognitionConfig {
11626    fn default() -> Self {
11627        Self {
11628            enabled: true,
11629            method: default_revenue_method(),
11630            completion_measure: default_completion_measure(),
11631            avg_contract_value: default_avg_contract_value(),
11632        }
11633    }
11634}
11635
11636/// Milestone configuration.
11637#[derive(Debug, Clone, Serialize, Deserialize)]
11638pub struct MilestoneSchemaConfig {
11639    /// Whether milestone generation is enabled.
11640    #[serde(default = "default_true")]
11641    pub enabled: bool,
11642    /// Average number of milestones per project.
11643    #[serde(default = "default_milestones_per_project")]
11644    pub avg_per_project: u32,
11645    /// Fraction of milestones that are payment milestones (0.0 to 1.0).
11646    #[serde(default = "default_payment_milestone_rate")]
11647    pub payment_milestone_rate: f64,
11648}
11649
11650fn default_milestones_per_project() -> u32 {
11651    4
11652}
11653fn default_payment_milestone_rate() -> f64 {
11654    0.50
11655}
11656
11657impl Default for MilestoneSchemaConfig {
11658    fn default() -> Self {
11659        Self {
11660            enabled: true,
11661            avg_per_project: default_milestones_per_project(),
11662            payment_milestone_rate: default_payment_milestone_rate(),
11663        }
11664    }
11665}
11666
11667/// Change order configuration.
11668#[derive(Debug, Clone, Serialize, Deserialize)]
11669pub struct ChangeOrderSchemaConfig {
11670    /// Whether change order generation is enabled.
11671    #[serde(default = "default_true")]
11672    pub enabled: bool,
11673    /// Probability that a project will have at least one change order (0.0 to 1.0).
11674    #[serde(default = "default_change_order_probability")]
11675    pub probability: f64,
11676    /// Maximum change orders per project.
11677    #[serde(default = "default_max_change_orders")]
11678    pub max_per_project: u32,
11679    /// Approval rate for change orders (0.0 to 1.0).
11680    #[serde(default = "default_change_order_approval_rate")]
11681    pub approval_rate: f64,
11682}
11683
11684fn default_change_order_probability() -> f64 {
11685    0.40
11686}
11687fn default_max_change_orders() -> u32 {
11688    3
11689}
11690fn default_change_order_approval_rate() -> f64 {
11691    0.75
11692}
11693
11694impl Default for ChangeOrderSchemaConfig {
11695    fn default() -> Self {
11696        Self {
11697            enabled: true,
11698            probability: default_change_order_probability(),
11699            max_per_project: default_max_change_orders(),
11700            approval_rate: default_change_order_approval_rate(),
11701        }
11702    }
11703}
11704
11705/// Retainage configuration.
11706#[derive(Debug, Clone, Serialize, Deserialize)]
11707pub struct RetainageSchemaConfig {
11708    /// Whether retainage is enabled.
11709    #[serde(default)]
11710    pub enabled: bool,
11711    /// Default retainage percentage (0.0 to 1.0, e.g., 0.10 for 10%).
11712    #[serde(default = "default_retainage_pct")]
11713    pub default_percentage: f64,
11714}
11715
11716fn default_retainage_pct() -> f64 {
11717    0.10
11718}
11719
11720impl Default for RetainageSchemaConfig {
11721    fn default() -> Self {
11722        Self {
11723            enabled: false,
11724            default_percentage: default_retainage_pct(),
11725        }
11726    }
11727}
11728
11729/// Earned value management (EVM) configuration.
11730#[derive(Debug, Clone, Serialize, Deserialize)]
11731pub struct EarnedValueSchemaConfig {
11732    /// Whether EVM metrics are generated.
11733    #[serde(default = "default_true")]
11734    pub enabled: bool,
11735    /// Measurement frequency: "weekly", "biweekly", "monthly".
11736    #[serde(default = "default_evm_frequency")]
11737    pub frequency: String,
11738}
11739
11740fn default_evm_frequency() -> String {
11741    "monthly".to_string()
11742}
11743
11744impl Default for EarnedValueSchemaConfig {
11745    fn default() -> Self {
11746        Self {
11747            enabled: true,
11748            frequency: default_evm_frequency(),
11749        }
11750    }
11751}
11752
11753// =============================================================================
11754// ESG / Sustainability Configuration
11755// =============================================================================
11756
11757/// Top-level ESG / sustainability reporting configuration.
11758#[derive(Debug, Clone, Serialize, Deserialize)]
11759pub struct EsgConfig {
11760    /// Whether ESG generation is enabled.
11761    #[serde(default)]
11762    pub enabled: bool,
11763    /// Environmental metrics (emissions, energy, water, waste).
11764    #[serde(default)]
11765    pub environmental: EnvironmentalConfig,
11766    /// Social metrics (diversity, pay equity, safety).
11767    #[serde(default)]
11768    pub social: SocialConfig,
11769    /// Governance metrics (board composition, ethics, compliance).
11770    #[serde(default)]
11771    pub governance: GovernanceSchemaConfig,
11772    /// Supply-chain ESG assessment settings.
11773    #[serde(default)]
11774    pub supply_chain_esg: SupplyChainEsgConfig,
11775    /// ESG reporting / disclosure framework settings.
11776    #[serde(default)]
11777    pub reporting: EsgReportingConfig,
11778    /// Climate scenario analysis settings.
11779    #[serde(default)]
11780    pub climate_scenarios: ClimateScenarioConfig,
11781    /// Anomaly injection rate for ESG data (0.0 to 1.0).
11782    #[serde(default = "default_esg_anomaly_rate")]
11783    pub anomaly_rate: f64,
11784}
11785
11786fn default_esg_anomaly_rate() -> f64 {
11787    0.02
11788}
11789
11790impl Default for EsgConfig {
11791    fn default() -> Self {
11792        Self {
11793            enabled: false,
11794            environmental: EnvironmentalConfig::default(),
11795            social: SocialConfig::default(),
11796            governance: GovernanceSchemaConfig::default(),
11797            supply_chain_esg: SupplyChainEsgConfig::default(),
11798            reporting: EsgReportingConfig::default(),
11799            climate_scenarios: ClimateScenarioConfig::default(),
11800            anomaly_rate: default_esg_anomaly_rate(),
11801        }
11802    }
11803}
11804
11805/// Country pack configuration.
11806///
11807/// Controls where to load additional country packs and per-country overrides.
11808/// When omitted, only the built-in packs (_default, US, DE, GB) are used.
11809#[derive(Debug, Clone, Serialize, Deserialize, Default)]
11810pub struct CountryPacksSchemaConfig {
11811    /// Optional directory containing additional `*.json` country packs.
11812    #[serde(default)]
11813    pub external_dir: Option<PathBuf>,
11814    /// Per-country overrides applied after loading.
11815    /// Keys are ISO 3166-1 alpha-2 codes; values are partial JSON objects
11816    /// that are deep-merged on top of the loaded pack.
11817    #[serde(default)]
11818    pub overrides: std::collections::HashMap<String, serde_json::Value>,
11819}
11820
11821/// Environmental metrics configuration.
11822#[derive(Debug, Clone, Serialize, Deserialize)]
11823pub struct EnvironmentalConfig {
11824    /// Whether environmental metrics are generated.
11825    #[serde(default = "default_true")]
11826    pub enabled: bool,
11827    /// Scope 1 (direct) emission generation settings.
11828    #[serde(default)]
11829    pub scope1: EmissionScopeConfig,
11830    /// Scope 2 (purchased energy) emission generation settings.
11831    #[serde(default)]
11832    pub scope2: EmissionScopeConfig,
11833    /// Scope 3 (value chain) emission generation settings.
11834    #[serde(default)]
11835    pub scope3: Scope3Config,
11836    /// Energy consumption tracking settings.
11837    #[serde(default)]
11838    pub energy: EnergySchemaConfig,
11839    /// Water usage tracking settings.
11840    #[serde(default)]
11841    pub water: WaterSchemaConfig,
11842    /// Waste management tracking settings.
11843    #[serde(default)]
11844    pub waste: WasteSchemaConfig,
11845}
11846
11847impl Default for EnvironmentalConfig {
11848    fn default() -> Self {
11849        Self {
11850            enabled: true,
11851            scope1: EmissionScopeConfig::default(),
11852            scope2: EmissionScopeConfig::default(),
11853            scope3: Scope3Config::default(),
11854            energy: EnergySchemaConfig::default(),
11855            water: WaterSchemaConfig::default(),
11856            waste: WasteSchemaConfig::default(),
11857        }
11858    }
11859}
11860
11861/// Configuration for a single emission scope (Scope 1 or 2).
11862#[derive(Debug, Clone, Serialize, Deserialize)]
11863pub struct EmissionScopeConfig {
11864    /// Whether this scope is enabled.
11865    #[serde(default = "default_true")]
11866    pub enabled: bool,
11867    /// Emission factor region (e.g., "US", "EU", "global").
11868    #[serde(default = "default_emission_region")]
11869    pub factor_region: String,
11870}
11871
11872fn default_emission_region() -> String {
11873    "US".to_string()
11874}
11875
11876impl Default for EmissionScopeConfig {
11877    fn default() -> Self {
11878        Self {
11879            enabled: true,
11880            factor_region: default_emission_region(),
11881        }
11882    }
11883}
11884
11885/// Scope 3 (value chain) emission configuration.
11886#[derive(Debug, Clone, Serialize, Deserialize)]
11887pub struct Scope3Config {
11888    /// Whether Scope 3 emissions are generated.
11889    #[serde(default = "default_true")]
11890    pub enabled: bool,
11891    /// Categories to include (e.g., "purchased_goods", "business_travel", "commuting").
11892    #[serde(default = "default_scope3_categories")]
11893    pub categories: Vec<String>,
11894    /// Spend-based emission intensity (kg CO2e per USD).
11895    #[serde(default = "default_spend_intensity")]
11896    pub default_spend_intensity_kg_per_usd: f64,
11897}
11898
11899fn default_scope3_categories() -> Vec<String> {
11900    vec![
11901        "purchased_goods".to_string(),
11902        "business_travel".to_string(),
11903        "employee_commuting".to_string(),
11904    ]
11905}
11906
11907fn default_spend_intensity() -> f64 {
11908    0.5
11909}
11910
11911impl Default for Scope3Config {
11912    fn default() -> Self {
11913        Self {
11914            enabled: true,
11915            categories: default_scope3_categories(),
11916            default_spend_intensity_kg_per_usd: default_spend_intensity(),
11917        }
11918    }
11919}
11920
11921/// Energy consumption configuration.
11922#[derive(Debug, Clone, Serialize, Deserialize)]
11923pub struct EnergySchemaConfig {
11924    /// Whether energy consumption tracking is enabled.
11925    #[serde(default = "default_true")]
11926    pub enabled: bool,
11927    /// Number of facilities to generate.
11928    #[serde(default = "default_facility_count")]
11929    pub facility_count: u32,
11930    /// Target percentage of energy from renewable sources (0.0 to 1.0).
11931    #[serde(default = "default_renewable_target")]
11932    pub renewable_target: f64,
11933}
11934
11935fn default_facility_count() -> u32 {
11936    5
11937}
11938
11939fn default_renewable_target() -> f64 {
11940    0.30
11941}
11942
11943impl Default for EnergySchemaConfig {
11944    fn default() -> Self {
11945        Self {
11946            enabled: true,
11947            facility_count: default_facility_count(),
11948            renewable_target: default_renewable_target(),
11949        }
11950    }
11951}
11952
11953/// Water usage configuration.
11954#[derive(Debug, Clone, Serialize, Deserialize)]
11955pub struct WaterSchemaConfig {
11956    /// Whether water usage tracking is enabled.
11957    #[serde(default = "default_true")]
11958    pub enabled: bool,
11959    /// Number of facilities with water tracking.
11960    #[serde(default = "default_water_facility_count")]
11961    pub facility_count: u32,
11962}
11963
11964fn default_water_facility_count() -> u32 {
11965    3
11966}
11967
11968impl Default for WaterSchemaConfig {
11969    fn default() -> Self {
11970        Self {
11971            enabled: true,
11972            facility_count: default_water_facility_count(),
11973        }
11974    }
11975}
11976
11977/// Waste management configuration.
11978#[derive(Debug, Clone, Serialize, Deserialize)]
11979pub struct WasteSchemaConfig {
11980    /// Whether waste tracking is enabled.
11981    #[serde(default = "default_true")]
11982    pub enabled: bool,
11983    /// Target diversion rate (0.0 to 1.0).
11984    #[serde(default = "default_diversion_target")]
11985    pub diversion_target: f64,
11986}
11987
11988fn default_diversion_target() -> f64 {
11989    0.50
11990}
11991
11992impl Default for WasteSchemaConfig {
11993    fn default() -> Self {
11994        Self {
11995            enabled: true,
11996            diversion_target: default_diversion_target(),
11997        }
11998    }
11999}
12000
12001/// Social metrics configuration.
12002#[derive(Debug, Clone, Serialize, Deserialize)]
12003pub struct SocialConfig {
12004    /// Whether social metrics are generated.
12005    #[serde(default = "default_true")]
12006    pub enabled: bool,
12007    /// Workforce diversity tracking settings.
12008    #[serde(default)]
12009    pub diversity: DiversitySchemaConfig,
12010    /// Pay equity analysis settings.
12011    #[serde(default)]
12012    pub pay_equity: PayEquitySchemaConfig,
12013    /// Safety incident and metrics settings.
12014    #[serde(default)]
12015    pub safety: SafetySchemaConfig,
12016}
12017
12018impl Default for SocialConfig {
12019    fn default() -> Self {
12020        Self {
12021            enabled: true,
12022            diversity: DiversitySchemaConfig::default(),
12023            pay_equity: PayEquitySchemaConfig::default(),
12024            safety: SafetySchemaConfig::default(),
12025        }
12026    }
12027}
12028
12029/// Workforce diversity configuration.
12030#[derive(Debug, Clone, Serialize, Deserialize)]
12031pub struct DiversitySchemaConfig {
12032    /// Whether diversity metrics are generated.
12033    #[serde(default = "default_true")]
12034    pub enabled: bool,
12035    /// Dimensions to track (e.g., "gender", "ethnicity", "age_group").
12036    #[serde(default = "default_diversity_dimensions")]
12037    pub dimensions: Vec<String>,
12038}
12039
12040fn default_diversity_dimensions() -> Vec<String> {
12041    vec![
12042        "gender".to_string(),
12043        "ethnicity".to_string(),
12044        "age_group".to_string(),
12045    ]
12046}
12047
12048impl Default for DiversitySchemaConfig {
12049    fn default() -> Self {
12050        Self {
12051            enabled: true,
12052            dimensions: default_diversity_dimensions(),
12053        }
12054    }
12055}
12056
12057/// Pay equity analysis configuration.
12058#[derive(Debug, Clone, Serialize, Deserialize)]
12059pub struct PayEquitySchemaConfig {
12060    /// Whether pay equity analysis is generated.
12061    #[serde(default = "default_true")]
12062    pub enabled: bool,
12063    /// Target pay gap threshold for flagging (e.g., 0.05 = 5% gap).
12064    #[serde(default = "default_pay_gap_threshold")]
12065    pub gap_threshold: f64,
12066}
12067
12068fn default_pay_gap_threshold() -> f64 {
12069    0.05
12070}
12071
12072impl Default for PayEquitySchemaConfig {
12073    fn default() -> Self {
12074        Self {
12075            enabled: true,
12076            gap_threshold: default_pay_gap_threshold(),
12077        }
12078    }
12079}
12080
12081/// Safety metrics configuration.
12082#[derive(Debug, Clone, Serialize, Deserialize)]
12083pub struct SafetySchemaConfig {
12084    /// Whether safety metrics are generated.
12085    #[serde(default = "default_true")]
12086    pub enabled: bool,
12087    /// Average annual recordable incidents per 200,000 hours.
12088    #[serde(default = "default_trir_target")]
12089    pub target_trir: f64,
12090    /// Number of safety incidents to generate.
12091    #[serde(default = "default_incident_count")]
12092    pub incident_count: u32,
12093}
12094
12095fn default_trir_target() -> f64 {
12096    2.5
12097}
12098
12099fn default_incident_count() -> u32 {
12100    20
12101}
12102
12103impl Default for SafetySchemaConfig {
12104    fn default() -> Self {
12105        Self {
12106            enabled: true,
12107            target_trir: default_trir_target(),
12108            incident_count: default_incident_count(),
12109        }
12110    }
12111}
12112
12113/// Governance metrics configuration.
12114#[derive(Debug, Clone, Serialize, Deserialize)]
12115pub struct GovernanceSchemaConfig {
12116    /// Whether governance metrics are generated.
12117    #[serde(default = "default_true")]
12118    pub enabled: bool,
12119    /// Number of board members.
12120    #[serde(default = "default_board_size")]
12121    pub board_size: u32,
12122    /// Target independent director ratio (0.0 to 1.0).
12123    #[serde(default = "default_independence_target")]
12124    pub independence_target: f64,
12125}
12126
12127fn default_board_size() -> u32 {
12128    11
12129}
12130
12131fn default_independence_target() -> f64 {
12132    0.67
12133}
12134
12135impl Default for GovernanceSchemaConfig {
12136    fn default() -> Self {
12137        Self {
12138            enabled: true,
12139            board_size: default_board_size(),
12140            independence_target: default_independence_target(),
12141        }
12142    }
12143}
12144
12145/// Supply-chain ESG assessment configuration.
12146#[derive(Debug, Clone, Serialize, Deserialize)]
12147pub struct SupplyChainEsgConfig {
12148    /// Whether supply chain ESG assessments are generated.
12149    #[serde(default = "default_true")]
12150    pub enabled: bool,
12151    /// Proportion of vendors to assess (0.0 to 1.0).
12152    #[serde(default = "default_assessment_coverage")]
12153    pub assessment_coverage: f64,
12154    /// High-risk country codes for automatic flagging.
12155    #[serde(default = "default_high_risk_countries")]
12156    pub high_risk_countries: Vec<String>,
12157}
12158
12159fn default_assessment_coverage() -> f64 {
12160    0.80
12161}
12162
12163fn default_high_risk_countries() -> Vec<String> {
12164    vec!["CN".to_string(), "BD".to_string(), "MM".to_string()]
12165}
12166
12167impl Default for SupplyChainEsgConfig {
12168    fn default() -> Self {
12169        Self {
12170            enabled: true,
12171            assessment_coverage: default_assessment_coverage(),
12172            high_risk_countries: default_high_risk_countries(),
12173        }
12174    }
12175}
12176
12177/// ESG reporting / disclosure framework configuration.
12178#[derive(Debug, Clone, Serialize, Deserialize)]
12179pub struct EsgReportingConfig {
12180    /// Whether ESG disclosures are generated.
12181    #[serde(default = "default_true")]
12182    pub enabled: bool,
12183    /// Frameworks to generate disclosures for.
12184    #[serde(default = "default_esg_frameworks")]
12185    pub frameworks: Vec<String>,
12186    /// Whether materiality assessment is performed.
12187    #[serde(default = "default_true")]
12188    pub materiality_assessment: bool,
12189    /// Materiality threshold for impact dimension (0.0 to 1.0).
12190    #[serde(default = "default_materiality_threshold")]
12191    pub impact_threshold: f64,
12192    /// Materiality threshold for financial dimension (0.0 to 1.0).
12193    #[serde(default = "default_materiality_threshold")]
12194    pub financial_threshold: f64,
12195}
12196
12197fn default_esg_frameworks() -> Vec<String> {
12198    vec!["GRI".to_string(), "ESRS".to_string()]
12199}
12200
12201fn default_materiality_threshold() -> f64 {
12202    0.6
12203}
12204
12205impl Default for EsgReportingConfig {
12206    fn default() -> Self {
12207        Self {
12208            enabled: true,
12209            frameworks: default_esg_frameworks(),
12210            materiality_assessment: true,
12211            impact_threshold: default_materiality_threshold(),
12212            financial_threshold: default_materiality_threshold(),
12213        }
12214    }
12215}
12216
12217/// Climate scenario analysis configuration.
12218#[derive(Debug, Clone, Serialize, Deserialize)]
12219pub struct ClimateScenarioConfig {
12220    /// Whether climate scenario analysis is generated.
12221    #[serde(default)]
12222    pub enabled: bool,
12223    /// Scenarios to model (e.g., "net_zero_2050", "stated_policies", "current_trajectory").
12224    #[serde(default = "default_climate_scenarios")]
12225    pub scenarios: Vec<String>,
12226    /// Time horizons in years to project.
12227    #[serde(default = "default_time_horizons")]
12228    pub time_horizons: Vec<u32>,
12229}
12230
12231fn default_climate_scenarios() -> Vec<String> {
12232    vec![
12233        "net_zero_2050".to_string(),
12234        "stated_policies".to_string(),
12235        "current_trajectory".to_string(),
12236    ]
12237}
12238
12239fn default_time_horizons() -> Vec<u32> {
12240    vec![5, 10, 30]
12241}
12242
12243impl Default for ClimateScenarioConfig {
12244    fn default() -> Self {
12245        Self {
12246            enabled: false,
12247            scenarios: default_climate_scenarios(),
12248            time_horizons: default_time_horizons(),
12249        }
12250    }
12251}
12252
12253#[cfg(test)]
12254#[allow(clippy::unwrap_used)]
12255mod tests {
12256    use super::*;
12257    use crate::presets::demo_preset;
12258
12259    // ==========================================================================
12260    // Serialization/Deserialization Tests
12261    // ==========================================================================
12262
12263    #[test]
12264    fn test_config_yaml_roundtrip() {
12265        let config = demo_preset();
12266        let yaml = serde_yaml::to_string(&config).expect("Failed to serialize to YAML");
12267        let deserialized: GeneratorConfig =
12268            serde_yaml::from_str(&yaml).expect("Failed to deserialize from YAML");
12269
12270        assert_eq!(
12271            config.global.period_months,
12272            deserialized.global.period_months
12273        );
12274        assert_eq!(config.global.industry, deserialized.global.industry);
12275        assert_eq!(config.companies.len(), deserialized.companies.len());
12276        assert_eq!(config.companies[0].code, deserialized.companies[0].code);
12277    }
12278
12279    #[test]
12280    fn test_config_json_roundtrip() {
12281        // Create a config without infinity values (JSON can't serialize f64::INFINITY)
12282        let mut config = demo_preset();
12283        // Replace infinity with a large but finite value for JSON compatibility
12284        config.master_data.employees.approval_limits.executive = 1e12;
12285
12286        let json = serde_json::to_string(&config).expect("Failed to serialize to JSON");
12287        let deserialized: GeneratorConfig =
12288            serde_json::from_str(&json).expect("Failed to deserialize from JSON");
12289
12290        assert_eq!(
12291            config.global.period_months,
12292            deserialized.global.period_months
12293        );
12294        assert_eq!(config.global.industry, deserialized.global.industry);
12295        assert_eq!(config.companies.len(), deserialized.companies.len());
12296    }
12297
12298    #[test]
12299    fn test_transaction_volume_serialization() {
12300        // Test various transaction volumes serialize correctly
12301        let volumes = vec![
12302            (TransactionVolume::TenK, "ten_k"),
12303            (TransactionVolume::HundredK, "hundred_k"),
12304            (TransactionVolume::OneM, "one_m"),
12305            (TransactionVolume::TenM, "ten_m"),
12306            (TransactionVolume::HundredM, "hundred_m"),
12307        ];
12308
12309        for (volume, expected_key) in volumes {
12310            let json = serde_json::to_string(&volume).expect("Failed to serialize");
12311            assert!(
12312                json.contains(expected_key),
12313                "Expected {} in JSON: {}",
12314                expected_key,
12315                json
12316            );
12317        }
12318    }
12319
12320    #[test]
12321    fn test_transaction_volume_custom_serialization() {
12322        let volume = TransactionVolume::Custom(12345);
12323        let json = serde_json::to_string(&volume).expect("Failed to serialize");
12324        let deserialized: TransactionVolume =
12325            serde_json::from_str(&json).expect("Failed to deserialize");
12326        assert_eq!(deserialized.count(), 12345);
12327    }
12328
12329    #[test]
12330    fn test_output_mode_serialization() {
12331        let modes = vec![
12332            OutputMode::Streaming,
12333            OutputMode::FlatFile,
12334            OutputMode::Both,
12335        ];
12336
12337        for mode in modes {
12338            let json = serde_json::to_string(&mode).expect("Failed to serialize");
12339            let deserialized: OutputMode =
12340                serde_json::from_str(&json).expect("Failed to deserialize");
12341            assert!(format!("{:?}", mode) == format!("{:?}", deserialized));
12342        }
12343    }
12344
12345    #[test]
12346    fn test_file_format_serialization() {
12347        let formats = vec![
12348            FileFormat::Csv,
12349            FileFormat::Parquet,
12350            FileFormat::Json,
12351            FileFormat::JsonLines,
12352        ];
12353
12354        for format in formats {
12355            let json = serde_json::to_string(&format).expect("Failed to serialize");
12356            let deserialized: FileFormat =
12357                serde_json::from_str(&json).expect("Failed to deserialize");
12358            assert!(format!("{:?}", format) == format!("{:?}", deserialized));
12359        }
12360    }
12361
12362    #[test]
12363    fn test_compression_algorithm_serialization() {
12364        let algos = vec![
12365            CompressionAlgorithm::Gzip,
12366            CompressionAlgorithm::Zstd,
12367            CompressionAlgorithm::Lz4,
12368            CompressionAlgorithm::Snappy,
12369        ];
12370
12371        for algo in algos {
12372            let json = serde_json::to_string(&algo).expect("Failed to serialize");
12373            let deserialized: CompressionAlgorithm =
12374                serde_json::from_str(&json).expect("Failed to deserialize");
12375            assert!(format!("{:?}", algo) == format!("{:?}", deserialized));
12376        }
12377    }
12378
12379    #[test]
12380    fn test_transfer_pricing_method_serialization() {
12381        let methods = vec![
12382            TransferPricingMethod::CostPlus,
12383            TransferPricingMethod::ComparableUncontrolled,
12384            TransferPricingMethod::ResalePrice,
12385            TransferPricingMethod::TransactionalNetMargin,
12386            TransferPricingMethod::ProfitSplit,
12387        ];
12388
12389        for method in methods {
12390            let json = serde_json::to_string(&method).expect("Failed to serialize");
12391            let deserialized: TransferPricingMethod =
12392                serde_json::from_str(&json).expect("Failed to deserialize");
12393            assert!(format!("{:?}", method) == format!("{:?}", deserialized));
12394        }
12395    }
12396
12397    #[test]
12398    fn test_benford_exemption_serialization() {
12399        let exemptions = vec![
12400            BenfordExemption::Recurring,
12401            BenfordExemption::Payroll,
12402            BenfordExemption::FixedFees,
12403            BenfordExemption::RoundAmounts,
12404        ];
12405
12406        for exemption in exemptions {
12407            let json = serde_json::to_string(&exemption).expect("Failed to serialize");
12408            let deserialized: BenfordExemption =
12409                serde_json::from_str(&json).expect("Failed to deserialize");
12410            assert!(format!("{:?}", exemption) == format!("{:?}", deserialized));
12411        }
12412    }
12413
12414    // ==========================================================================
12415    // Default Value Tests
12416    // ==========================================================================
12417
12418    #[test]
12419    fn test_global_config_defaults() {
12420        let yaml = r#"
12421            industry: manufacturing
12422            start_date: "2024-01-01"
12423            period_months: 6
12424        "#;
12425        let config: GlobalConfig = serde_yaml::from_str(yaml).expect("Failed to parse");
12426        assert_eq!(config.group_currency, "USD");
12427        assert!(config.parallel);
12428        assert_eq!(config.worker_threads, 0);
12429        assert_eq!(config.memory_limit_mb, 0);
12430    }
12431
12432    #[test]
12433    fn test_fraud_config_defaults() {
12434        let config = FraudConfig::default();
12435        assert!(!config.enabled);
12436        assert_eq!(config.fraud_rate, 0.005);
12437        assert!(!config.clustering_enabled);
12438    }
12439
12440    #[test]
12441    fn test_internal_controls_config_defaults() {
12442        let config = InternalControlsConfig::default();
12443        assert!(!config.enabled);
12444        assert_eq!(config.exception_rate, 0.02);
12445        assert_eq!(config.sod_violation_rate, 0.01);
12446        assert!(config.export_control_master_data);
12447        assert_eq!(config.sox_materiality_threshold, 10000.0);
12448        // COSO fields
12449        assert!(config.coso_enabled);
12450        assert!(!config.include_entity_level_controls);
12451        assert_eq!(config.target_maturity_level, "mixed");
12452    }
12453
12454    #[test]
12455    fn test_output_config_defaults() {
12456        let config = OutputConfig::default();
12457        assert!(matches!(config.mode, OutputMode::FlatFile));
12458        assert_eq!(config.formats, vec![FileFormat::Parquet]);
12459        assert!(config.compression.enabled);
12460        assert!(matches!(
12461            config.compression.algorithm,
12462            CompressionAlgorithm::Zstd
12463        ));
12464        assert!(config.include_acdoca);
12465        assert!(!config.include_bseg);
12466        assert!(config.partition_by_period);
12467        assert!(!config.partition_by_company);
12468    }
12469
12470    #[test]
12471    fn test_approval_config_defaults() {
12472        let config = ApprovalConfig::default();
12473        assert!(!config.enabled);
12474        assert_eq!(config.auto_approve_threshold, 1000.0);
12475        assert_eq!(config.rejection_rate, 0.02);
12476        assert_eq!(config.revision_rate, 0.05);
12477        assert_eq!(config.average_approval_delay_hours, 4.0);
12478        assert_eq!(config.thresholds.len(), 4);
12479    }
12480
12481    #[test]
12482    fn test_p2p_flow_config_defaults() {
12483        let config = P2PFlowConfig::default();
12484        assert!(config.enabled);
12485        assert_eq!(config.three_way_match_rate, 0.95);
12486        assert_eq!(config.partial_delivery_rate, 0.15);
12487        assert_eq!(config.average_po_to_gr_days, 14);
12488    }
12489
12490    #[test]
12491    fn test_o2c_flow_config_defaults() {
12492        let config = O2CFlowConfig::default();
12493        assert!(config.enabled);
12494        assert_eq!(config.credit_check_failure_rate, 0.02);
12495        assert_eq!(config.return_rate, 0.03);
12496        assert_eq!(config.bad_debt_rate, 0.01);
12497    }
12498
12499    #[test]
12500    fn test_balance_config_defaults() {
12501        let config = BalanceConfig::default();
12502        assert!(!config.generate_opening_balances);
12503        assert!(config.generate_trial_balances);
12504        assert_eq!(config.target_gross_margin, 0.35);
12505        assert!(config.validate_balance_equation);
12506        assert!(config.reconcile_subledgers);
12507    }
12508
12509    // ==========================================================================
12510    // Partial Config Deserialization Tests
12511    // ==========================================================================
12512
12513    #[test]
12514    fn test_partial_config_with_defaults() {
12515        // Minimal config that should use all defaults
12516        let yaml = r#"
12517            global:
12518              industry: manufacturing
12519              start_date: "2024-01-01"
12520              period_months: 3
12521            companies:
12522              - code: "TEST"
12523                name: "Test Company"
12524                currency: "USD"
12525                country: "US"
12526                annual_transaction_volume: ten_k
12527            chart_of_accounts:
12528              complexity: small
12529            output:
12530              output_directory: "./output"
12531        "#;
12532
12533        let config: GeneratorConfig = serde_yaml::from_str(yaml).expect("Failed to parse");
12534        assert_eq!(config.global.period_months, 3);
12535        assert_eq!(config.companies.len(), 1);
12536        assert!(!config.fraud.enabled); // Default
12537        assert!(!config.internal_controls.enabled); // Default
12538    }
12539
12540    #[test]
12541    fn test_config_with_fraud_enabled() {
12542        let yaml = r#"
12543            global:
12544              industry: retail
12545              start_date: "2024-01-01"
12546              period_months: 12
12547            companies:
12548              - code: "RETAIL"
12549                name: "Retail Co"
12550                currency: "USD"
12551                country: "US"
12552                annual_transaction_volume: hundred_k
12553            chart_of_accounts:
12554              complexity: medium
12555            output:
12556              output_directory: "./output"
12557            fraud:
12558              enabled: true
12559              fraud_rate: 0.05
12560              clustering_enabled: true
12561        "#;
12562
12563        let config: GeneratorConfig = serde_yaml::from_str(yaml).expect("Failed to parse");
12564        assert!(config.fraud.enabled);
12565        assert_eq!(config.fraud.fraud_rate, 0.05);
12566        assert!(config.fraud.clustering_enabled);
12567    }
12568
12569    #[test]
12570    fn test_config_with_multiple_companies() {
12571        let yaml = r#"
12572            global:
12573              industry: manufacturing
12574              start_date: "2024-01-01"
12575              period_months: 6
12576            companies:
12577              - code: "HQ"
12578                name: "Headquarters"
12579                currency: "USD"
12580                country: "US"
12581                annual_transaction_volume: hundred_k
12582                volume_weight: 1.0
12583              - code: "EU"
12584                name: "European Subsidiary"
12585                currency: "EUR"
12586                country: "DE"
12587                annual_transaction_volume: hundred_k
12588                volume_weight: 0.5
12589              - code: "APAC"
12590                name: "Asia Pacific"
12591                currency: "JPY"
12592                country: "JP"
12593                annual_transaction_volume: ten_k
12594                volume_weight: 0.3
12595            chart_of_accounts:
12596              complexity: large
12597            output:
12598              output_directory: "./output"
12599        "#;
12600
12601        let config: GeneratorConfig = serde_yaml::from_str(yaml).expect("Failed to parse");
12602        assert_eq!(config.companies.len(), 3);
12603        assert_eq!(config.companies[0].code, "HQ");
12604        assert_eq!(config.companies[1].currency, "EUR");
12605        assert_eq!(config.companies[2].volume_weight, 0.3);
12606    }
12607
12608    #[test]
12609    fn test_intercompany_config() {
12610        let yaml = r#"
12611            enabled: true
12612            ic_transaction_rate: 0.20
12613            transfer_pricing_method: cost_plus
12614            markup_percent: 0.08
12615            generate_matched_pairs: true
12616            generate_eliminations: true
12617        "#;
12618
12619        let config: IntercompanyConfig = serde_yaml::from_str(yaml).expect("Failed to parse");
12620        assert!(config.enabled);
12621        assert_eq!(config.ic_transaction_rate, 0.20);
12622        assert!(matches!(
12623            config.transfer_pricing_method,
12624            TransferPricingMethod::CostPlus
12625        ));
12626        assert_eq!(config.markup_percent, 0.08);
12627        assert!(config.generate_eliminations);
12628    }
12629
12630    // ==========================================================================
12631    // Company Config Tests
12632    // ==========================================================================
12633
12634    #[test]
12635    fn test_company_config_defaults() {
12636        let yaml = r#"
12637            code: "TEST"
12638            name: "Test Company"
12639            currency: "USD"
12640            country: "US"
12641            annual_transaction_volume: ten_k
12642        "#;
12643
12644        let config: CompanyConfig = serde_yaml::from_str(yaml).expect("Failed to parse");
12645        assert_eq!(config.fiscal_year_variant, "K4"); // Default
12646        assert_eq!(config.volume_weight, 1.0); // Default
12647    }
12648
12649    // ==========================================================================
12650    // Chart of Accounts Config Tests
12651    // ==========================================================================
12652
12653    #[test]
12654    fn test_coa_config_defaults() {
12655        let yaml = r#"
12656            complexity: medium
12657        "#;
12658
12659        let config: ChartOfAccountsConfig = serde_yaml::from_str(yaml).expect("Failed to parse");
12660        assert!(config.industry_specific); // Default true
12661        assert!(config.custom_accounts.is_none());
12662        assert_eq!(config.min_hierarchy_depth, 2); // Default
12663        assert_eq!(config.max_hierarchy_depth, 5); // Default
12664    }
12665
12666    // ==========================================================================
12667    // Accounting Standards Config Tests
12668    // ==========================================================================
12669
12670    #[test]
12671    fn test_accounting_standards_config_defaults() {
12672        let config = AccountingStandardsConfig::default();
12673        assert!(!config.enabled);
12674        assert!(config.framework.is_none());
12675        assert!(!config.revenue_recognition.enabled);
12676        assert!(!config.leases.enabled);
12677        assert!(!config.fair_value.enabled);
12678        assert!(!config.impairment.enabled);
12679        assert!(!config.generate_differences);
12680    }
12681
12682    #[test]
12683    fn test_accounting_standards_config_yaml() {
12684        let yaml = r#"
12685            enabled: true
12686            framework: ifrs
12687            revenue_recognition:
12688              enabled: true
12689              generate_contracts: true
12690              avg_obligations_per_contract: 2.5
12691              variable_consideration_rate: 0.20
12692              over_time_recognition_rate: 0.35
12693              contract_count: 150
12694            leases:
12695              enabled: true
12696              lease_count: 75
12697              finance_lease_percent: 0.25
12698              avg_lease_term_months: 48
12699            generate_differences: true
12700        "#;
12701
12702        let config: AccountingStandardsConfig =
12703            serde_yaml::from_str(yaml).expect("Failed to parse");
12704        assert!(config.enabled);
12705        assert!(matches!(
12706            config.framework,
12707            Some(AccountingFrameworkConfig::Ifrs)
12708        ));
12709        assert!(config.revenue_recognition.enabled);
12710        assert_eq!(config.revenue_recognition.contract_count, 150);
12711        assert_eq!(config.revenue_recognition.avg_obligations_per_contract, 2.5);
12712        assert!(config.leases.enabled);
12713        assert_eq!(config.leases.lease_count, 75);
12714        assert_eq!(config.leases.finance_lease_percent, 0.25);
12715        assert!(config.generate_differences);
12716    }
12717
12718    #[test]
12719    fn test_accounting_framework_serialization() {
12720        let frameworks = [
12721            AccountingFrameworkConfig::UsGaap,
12722            AccountingFrameworkConfig::Ifrs,
12723            AccountingFrameworkConfig::DualReporting,
12724            AccountingFrameworkConfig::FrenchGaap,
12725        ];
12726
12727        for framework in frameworks {
12728            let json = serde_json::to_string(&framework).expect("Failed to serialize");
12729            let deserialized: AccountingFrameworkConfig =
12730                serde_json::from_str(&json).expect("Failed to deserialize");
12731            assert!(format!("{:?}", framework) == format!("{:?}", deserialized));
12732        }
12733    }
12734
12735    #[test]
12736    fn test_revenue_recognition_config_defaults() {
12737        let config = RevenueRecognitionConfig::default();
12738        assert!(!config.enabled);
12739        assert!(config.generate_contracts);
12740        assert_eq!(config.avg_obligations_per_contract, 2.0);
12741        assert_eq!(config.variable_consideration_rate, 0.15);
12742        assert_eq!(config.over_time_recognition_rate, 0.30);
12743        assert_eq!(config.contract_count, 100);
12744    }
12745
12746    #[test]
12747    fn test_lease_accounting_config_defaults() {
12748        let config = LeaseAccountingConfig::default();
12749        assert!(!config.enabled);
12750        assert_eq!(config.lease_count, 50);
12751        assert_eq!(config.finance_lease_percent, 0.30);
12752        assert_eq!(config.avg_lease_term_months, 60);
12753        assert!(config.generate_amortization);
12754        assert_eq!(config.real_estate_percent, 0.40);
12755    }
12756
12757    #[test]
12758    fn test_fair_value_config_defaults() {
12759        let config = FairValueConfig::default();
12760        assert!(!config.enabled);
12761        assert_eq!(config.measurement_count, 25);
12762        assert_eq!(config.level1_percent, 0.40);
12763        assert_eq!(config.level2_percent, 0.35);
12764        assert_eq!(config.level3_percent, 0.25);
12765        assert!(!config.include_sensitivity_analysis);
12766    }
12767
12768    #[test]
12769    fn test_impairment_config_defaults() {
12770        let config = ImpairmentConfig::default();
12771        assert!(!config.enabled);
12772        assert_eq!(config.test_count, 15);
12773        assert_eq!(config.impairment_rate, 0.10);
12774        assert!(config.generate_projections);
12775        assert!(!config.include_goodwill);
12776    }
12777
12778    // ==========================================================================
12779    // Audit Standards Config Tests
12780    // ==========================================================================
12781
12782    #[test]
12783    fn test_audit_standards_config_defaults() {
12784        let config = AuditStandardsConfig::default();
12785        assert!(!config.enabled);
12786        assert!(!config.isa_compliance.enabled);
12787        assert!(!config.analytical_procedures.enabled);
12788        assert!(!config.confirmations.enabled);
12789        assert!(!config.opinion.enabled);
12790        assert!(!config.generate_audit_trail);
12791        assert!(!config.sox.enabled);
12792        assert!(!config.pcaob.enabled);
12793    }
12794
12795    #[test]
12796    fn test_audit_standards_config_yaml() {
12797        let yaml = r#"
12798            enabled: true
12799            isa_compliance:
12800              enabled: true
12801              compliance_level: comprehensive
12802              generate_isa_mappings: true
12803              include_pcaob: true
12804              framework: dual
12805            analytical_procedures:
12806              enabled: true
12807              procedures_per_account: 5
12808              variance_probability: 0.25
12809            confirmations:
12810              enabled: true
12811              confirmation_count: 75
12812              positive_response_rate: 0.90
12813              exception_rate: 0.08
12814            opinion:
12815              enabled: true
12816              generate_kam: true
12817              average_kam_count: 4
12818            sox:
12819              enabled: true
12820              generate_302_certifications: true
12821              generate_404_assessments: true
12822              material_weakness_rate: 0.03
12823            pcaob:
12824              enabled: true
12825              is_pcaob_audit: true
12826              include_icfr_opinion: true
12827            generate_audit_trail: true
12828        "#;
12829
12830        let config: AuditStandardsConfig = serde_yaml::from_str(yaml).expect("Failed to parse");
12831        assert!(config.enabled);
12832        assert!(config.isa_compliance.enabled);
12833        assert_eq!(config.isa_compliance.compliance_level, "comprehensive");
12834        assert!(config.isa_compliance.include_pcaob);
12835        assert_eq!(config.isa_compliance.framework, "dual");
12836        assert!(config.analytical_procedures.enabled);
12837        assert_eq!(config.analytical_procedures.procedures_per_account, 5);
12838        assert!(config.confirmations.enabled);
12839        assert_eq!(config.confirmations.confirmation_count, 75);
12840        assert!(config.opinion.enabled);
12841        assert_eq!(config.opinion.average_kam_count, 4);
12842        assert!(config.sox.enabled);
12843        assert!(config.sox.generate_302_certifications);
12844        assert_eq!(config.sox.material_weakness_rate, 0.03);
12845        assert!(config.pcaob.enabled);
12846        assert!(config.pcaob.is_pcaob_audit);
12847        assert!(config.pcaob.include_icfr_opinion);
12848        assert!(config.generate_audit_trail);
12849    }
12850
12851    #[test]
12852    fn test_isa_compliance_config_defaults() {
12853        let config = IsaComplianceConfig::default();
12854        assert!(!config.enabled);
12855        assert_eq!(config.compliance_level, "standard");
12856        assert!(config.generate_isa_mappings);
12857        assert!(config.generate_coverage_summary);
12858        assert!(!config.include_pcaob);
12859        assert_eq!(config.framework, "isa");
12860    }
12861
12862    #[test]
12863    fn test_sox_compliance_config_defaults() {
12864        let config = SoxComplianceConfig::default();
12865        assert!(!config.enabled);
12866        assert!(config.generate_302_certifications);
12867        assert!(config.generate_404_assessments);
12868        assert_eq!(config.materiality_threshold, 10000.0);
12869        assert_eq!(config.material_weakness_rate, 0.02);
12870        assert_eq!(config.significant_deficiency_rate, 0.08);
12871    }
12872
12873    #[test]
12874    fn test_pcaob_config_defaults() {
12875        let config = PcaobConfig::default();
12876        assert!(!config.enabled);
12877        assert!(!config.is_pcaob_audit);
12878        assert!(config.generate_cam);
12879        assert!(!config.include_icfr_opinion);
12880        assert!(!config.generate_standard_mappings);
12881    }
12882
12883    #[test]
12884    fn test_config_with_standards_enabled() {
12885        let yaml = r#"
12886            global:
12887              industry: financial_services
12888              start_date: "2024-01-01"
12889              period_months: 12
12890            companies:
12891              - code: "BANK"
12892                name: "Test Bank"
12893                currency: "USD"
12894                country: "US"
12895                annual_transaction_volume: hundred_k
12896            chart_of_accounts:
12897              complexity: large
12898            output:
12899              output_directory: "./output"
12900            accounting_standards:
12901              enabled: true
12902              framework: us_gaap
12903              revenue_recognition:
12904                enabled: true
12905              leases:
12906                enabled: true
12907            audit_standards:
12908              enabled: true
12909              isa_compliance:
12910                enabled: true
12911              sox:
12912                enabled: true
12913        "#;
12914
12915        let config: GeneratorConfig = serde_yaml::from_str(yaml).expect("Failed to parse");
12916        assert!(config.accounting_standards.enabled);
12917        assert!(matches!(
12918            config.accounting_standards.framework,
12919            Some(AccountingFrameworkConfig::UsGaap)
12920        ));
12921        assert!(config.accounting_standards.revenue_recognition.enabled);
12922        assert!(config.accounting_standards.leases.enabled);
12923        assert!(config.audit_standards.enabled);
12924        assert!(config.audit_standards.isa_compliance.enabled);
12925        assert!(config.audit_standards.sox.enabled);
12926    }
12927
12928    // ==========================================================================
12929    // Industry-Specific Config Tests
12930    // ==========================================================================
12931
12932    #[test]
12933    fn test_industry_specific_config_defaults() {
12934        let config = IndustrySpecificConfig::default();
12935        assert!(!config.enabled);
12936        assert!(!config.manufacturing.enabled);
12937        assert!(!config.retail.enabled);
12938        assert!(!config.healthcare.enabled);
12939        assert!(!config.technology.enabled);
12940        assert!(!config.financial_services.enabled);
12941        assert!(!config.professional_services.enabled);
12942    }
12943
12944    #[test]
12945    fn test_manufacturing_config_defaults() {
12946        let config = ManufacturingConfig::default();
12947        assert!(!config.enabled);
12948        assert_eq!(config.bom_depth, 4);
12949        assert!(!config.just_in_time);
12950        assert_eq!(config.supplier_tiers, 2);
12951        assert_eq!(config.target_yield_rate, 0.97);
12952        assert_eq!(config.scrap_alert_threshold, 0.03);
12953    }
12954
12955    #[test]
12956    fn test_retail_config_defaults() {
12957        let config = RetailConfig::default();
12958        assert!(!config.enabled);
12959        assert_eq!(config.avg_daily_transactions, 500);
12960        assert!(config.loss_prevention);
12961        assert_eq!(config.shrinkage_rate, 0.015);
12962    }
12963
12964    #[test]
12965    fn test_healthcare_config_defaults() {
12966        let config = HealthcareConfig::default();
12967        assert!(!config.enabled);
12968        assert_eq!(config.facility_type, "hospital");
12969        assert_eq!(config.avg_daily_encounters, 150);
12970        assert!(config.compliance.hipaa);
12971        assert!(config.compliance.stark_law);
12972        assert!(config.coding_systems.icd10);
12973        assert!(config.coding_systems.cpt);
12974    }
12975
12976    #[test]
12977    fn test_technology_config_defaults() {
12978        let config = TechnologyConfig::default();
12979        assert!(!config.enabled);
12980        assert_eq!(config.revenue_model, "saas");
12981        assert_eq!(config.subscription_revenue_pct, 0.60);
12982        assert!(config.rd_capitalization.enabled);
12983    }
12984
12985    #[test]
12986    fn test_config_with_industry_specific() {
12987        let yaml = r#"
12988            global:
12989              industry: healthcare
12990              start_date: "2024-01-01"
12991              period_months: 12
12992            companies:
12993              - code: "HOSP"
12994                name: "Test Hospital"
12995                currency: "USD"
12996                country: "US"
12997                annual_transaction_volume: hundred_k
12998            chart_of_accounts:
12999              complexity: medium
13000            output:
13001              output_directory: "./output"
13002            industry_specific:
13003              enabled: true
13004              healthcare:
13005                enabled: true
13006                facility_type: hospital
13007                payer_mix:
13008                  medicare: 0.45
13009                  medicaid: 0.15
13010                  commercial: 0.35
13011                  self_pay: 0.05
13012                coding_systems:
13013                  icd10: true
13014                  cpt: true
13015                  drg: true
13016                compliance:
13017                  hipaa: true
13018                  stark_law: true
13019                anomaly_rates:
13020                  upcoding: 0.03
13021                  unbundling: 0.02
13022        "#;
13023
13024        let config: GeneratorConfig = serde_yaml::from_str(yaml).expect("Failed to parse");
13025        assert!(config.industry_specific.enabled);
13026        assert!(config.industry_specific.healthcare.enabled);
13027        assert_eq!(
13028            config.industry_specific.healthcare.facility_type,
13029            "hospital"
13030        );
13031        assert_eq!(config.industry_specific.healthcare.payer_mix.medicare, 0.45);
13032        assert_eq!(config.industry_specific.healthcare.payer_mix.self_pay, 0.05);
13033        assert!(config.industry_specific.healthcare.coding_systems.icd10);
13034        assert!(config.industry_specific.healthcare.compliance.hipaa);
13035        assert_eq!(
13036            config.industry_specific.healthcare.anomaly_rates.upcoding,
13037            0.03
13038        );
13039    }
13040
13041    #[test]
13042    fn test_config_with_manufacturing_specific() {
13043        let yaml = r#"
13044            global:
13045              industry: manufacturing
13046              start_date: "2024-01-01"
13047              period_months: 12
13048            companies:
13049              - code: "MFG"
13050                name: "Test Manufacturing"
13051                currency: "USD"
13052                country: "US"
13053                annual_transaction_volume: hundred_k
13054            chart_of_accounts:
13055              complexity: medium
13056            output:
13057              output_directory: "./output"
13058            industry_specific:
13059              enabled: true
13060              manufacturing:
13061                enabled: true
13062                bom_depth: 5
13063                just_in_time: true
13064                supplier_tiers: 3
13065                target_yield_rate: 0.98
13066                anomaly_rates:
13067                  yield_manipulation: 0.02
13068                  phantom_production: 0.01
13069        "#;
13070
13071        let config: GeneratorConfig = serde_yaml::from_str(yaml).expect("Failed to parse");
13072        assert!(config.industry_specific.enabled);
13073        assert!(config.industry_specific.manufacturing.enabled);
13074        assert_eq!(config.industry_specific.manufacturing.bom_depth, 5);
13075        assert!(config.industry_specific.manufacturing.just_in_time);
13076        assert_eq!(config.industry_specific.manufacturing.supplier_tiers, 3);
13077        assert_eq!(
13078            config.industry_specific.manufacturing.target_yield_rate,
13079            0.98
13080        );
13081        assert_eq!(
13082            config
13083                .industry_specific
13084                .manufacturing
13085                .anomaly_rates
13086                .yield_manipulation,
13087            0.02
13088        );
13089    }
13090
13091    // ==========================================================================
13092    // Tax Configuration Tests
13093    // ==========================================================================
13094
13095    #[test]
13096    fn test_tax_config_defaults() {
13097        let tax = TaxConfig::default();
13098        assert!(!tax.enabled);
13099        assert!(tax.jurisdictions.countries.is_empty());
13100        assert!(!tax.jurisdictions.include_subnational);
13101        assert!(!tax.vat_gst.enabled);
13102        assert!(tax.vat_gst.standard_rates.is_empty());
13103        assert!(tax.vat_gst.reduced_rates.is_empty());
13104        assert!(tax.vat_gst.exempt_categories.is_empty());
13105        assert!(tax.vat_gst.reverse_charge);
13106        assert!(!tax.sales_tax.enabled);
13107        assert!(tax.sales_tax.nexus_states.is_empty());
13108        assert!(!tax.withholding.enabled);
13109        assert!(tax.withholding.treaty_network);
13110        assert_eq!(tax.withholding.default_rate, 0.30);
13111        assert_eq!(tax.withholding.treaty_reduced_rate, 0.15);
13112        assert!(tax.provisions.enabled);
13113        assert_eq!(tax.provisions.statutory_rate, 0.21);
13114        assert!(tax.provisions.uncertain_positions);
13115        assert!(!tax.payroll_tax.enabled);
13116        assert_eq!(tax.anomaly_rate, 0.03);
13117    }
13118
13119    #[test]
13120    fn test_tax_config_from_yaml() {
13121        let yaml = r#"
13122            global:
13123              seed: 42
13124              start_date: "2024-01-01"
13125              period_months: 12
13126              industry: retail
13127            companies:
13128              - code: C001
13129                name: Test Corp
13130                currency: USD
13131                country: US
13132                annual_transaction_volume: ten_k
13133            chart_of_accounts:
13134              complexity: small
13135            output:
13136              output_directory: ./output
13137            tax:
13138              enabled: true
13139              anomaly_rate: 0.05
13140              jurisdictions:
13141                countries: ["US", "DE", "GB"]
13142                include_subnational: true
13143              vat_gst:
13144                enabled: true
13145                standard_rates:
13146                  DE: 0.19
13147                  GB: 0.20
13148                reduced_rates:
13149                  DE: 0.07
13150                  GB: 0.05
13151                exempt_categories:
13152                  - financial_services
13153                  - healthcare
13154                reverse_charge: false
13155              sales_tax:
13156                enabled: true
13157                nexus_states: ["CA", "NY", "TX"]
13158              withholding:
13159                enabled: true
13160                treaty_network: false
13161                default_rate: 0.25
13162                treaty_reduced_rate: 0.10
13163              provisions:
13164                enabled: false
13165                statutory_rate: 0.28
13166                uncertain_positions: false
13167              payroll_tax:
13168                enabled: true
13169        "#;
13170
13171        let config: GeneratorConfig = serde_yaml::from_str(yaml).expect("Failed to parse");
13172        assert!(config.tax.enabled);
13173        assert_eq!(config.tax.anomaly_rate, 0.05);
13174
13175        // Jurisdictions
13176        assert_eq!(config.tax.jurisdictions.countries.len(), 3);
13177        assert!(config
13178            .tax
13179            .jurisdictions
13180            .countries
13181            .contains(&"DE".to_string()));
13182        assert!(config.tax.jurisdictions.include_subnational);
13183
13184        // VAT/GST
13185        assert!(config.tax.vat_gst.enabled);
13186        assert_eq!(config.tax.vat_gst.standard_rates.get("DE"), Some(&0.19));
13187        assert_eq!(config.tax.vat_gst.standard_rates.get("GB"), Some(&0.20));
13188        assert_eq!(config.tax.vat_gst.reduced_rates.get("DE"), Some(&0.07));
13189        assert_eq!(config.tax.vat_gst.exempt_categories.len(), 2);
13190        assert!(!config.tax.vat_gst.reverse_charge);
13191
13192        // Sales tax
13193        assert!(config.tax.sales_tax.enabled);
13194        assert_eq!(config.tax.sales_tax.nexus_states.len(), 3);
13195        assert!(config
13196            .tax
13197            .sales_tax
13198            .nexus_states
13199            .contains(&"CA".to_string()));
13200
13201        // Withholding
13202        assert!(config.tax.withholding.enabled);
13203        assert!(!config.tax.withholding.treaty_network);
13204        assert_eq!(config.tax.withholding.default_rate, 0.25);
13205        assert_eq!(config.tax.withholding.treaty_reduced_rate, 0.10);
13206
13207        // Provisions
13208        assert!(!config.tax.provisions.enabled);
13209        assert_eq!(config.tax.provisions.statutory_rate, 0.28);
13210        assert!(!config.tax.provisions.uncertain_positions);
13211
13212        // Payroll tax
13213        assert!(config.tax.payroll_tax.enabled);
13214    }
13215
13216    #[test]
13217    fn test_generator_config_with_tax_default() {
13218        let yaml = r#"
13219            global:
13220              seed: 42
13221              start_date: "2024-01-01"
13222              period_months: 12
13223              industry: retail
13224            companies:
13225              - code: C001
13226                name: Test Corp
13227                currency: USD
13228                country: US
13229                annual_transaction_volume: ten_k
13230            chart_of_accounts:
13231              complexity: small
13232            output:
13233              output_directory: ./output
13234        "#;
13235
13236        let config: GeneratorConfig =
13237            serde_yaml::from_str(yaml).expect("Failed to parse config without tax section");
13238        // Tax should be present with defaults when not specified in YAML
13239        assert!(!config.tax.enabled);
13240        assert!(config.tax.jurisdictions.countries.is_empty());
13241        assert_eq!(config.tax.anomaly_rate, 0.03);
13242        assert!(config.tax.provisions.enabled); // provisions default to enabled=true
13243        assert_eq!(config.tax.provisions.statutory_rate, 0.21);
13244    }
13245}