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 and IFRS frameworks with specific standards:
4641/// - ASC 606/IFRS 15: Revenue Recognition
4642/// - ASC 842/IFRS 16: Leases
4643/// - ASC 820/IFRS 13: Fair Value Measurement
4644/// - ASC 360/IAS 36: 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}
4690
4691/// Revenue recognition configuration (ASC 606/IFRS 15).
4692#[derive(Debug, Clone, Serialize, Deserialize)]
4693pub struct RevenueRecognitionConfig {
4694    /// Enable revenue recognition generation
4695    #[serde(default)]
4696    pub enabled: bool,
4697
4698    /// Generate customer contracts
4699    #[serde(default = "default_true")]
4700    pub generate_contracts: bool,
4701
4702    /// Average number of performance obligations per contract
4703    #[serde(default = "default_avg_obligations")]
4704    pub avg_obligations_per_contract: f64,
4705
4706    /// Rate of contracts with variable consideration
4707    #[serde(default = "default_variable_consideration_rate")]
4708    pub variable_consideration_rate: f64,
4709
4710    /// Rate of over-time revenue recognition (vs point-in-time)
4711    #[serde(default = "default_over_time_rate")]
4712    pub over_time_recognition_rate: f64,
4713
4714    /// Number of contracts to generate
4715    #[serde(default = "default_contract_count")]
4716    pub contract_count: usize,
4717}
4718
4719fn default_avg_obligations() -> f64 {
4720    2.0
4721}
4722
4723fn default_variable_consideration_rate() -> f64 {
4724    0.15
4725}
4726
4727fn default_over_time_rate() -> f64 {
4728    0.30
4729}
4730
4731fn default_contract_count() -> usize {
4732    100
4733}
4734
4735impl Default for RevenueRecognitionConfig {
4736    fn default() -> Self {
4737        Self {
4738            enabled: false,
4739            generate_contracts: true,
4740            avg_obligations_per_contract: default_avg_obligations(),
4741            variable_consideration_rate: default_variable_consideration_rate(),
4742            over_time_recognition_rate: default_over_time_rate(),
4743            contract_count: default_contract_count(),
4744        }
4745    }
4746}
4747
4748/// Lease accounting configuration (ASC 842/IFRS 16).
4749#[derive(Debug, Clone, Serialize, Deserialize)]
4750pub struct LeaseAccountingConfig {
4751    /// Enable lease accounting generation
4752    #[serde(default)]
4753    pub enabled: bool,
4754
4755    /// Number of leases to generate
4756    #[serde(default = "default_lease_count")]
4757    pub lease_count: usize,
4758
4759    /// Percentage of finance leases (vs operating)
4760    #[serde(default = "default_finance_lease_pct")]
4761    pub finance_lease_percent: f64,
4762
4763    /// Average lease term in months
4764    #[serde(default = "default_avg_lease_term")]
4765    pub avg_lease_term_months: u32,
4766
4767    /// Generate amortization schedules
4768    #[serde(default = "default_true")]
4769    pub generate_amortization: bool,
4770
4771    /// Real estate lease percentage
4772    #[serde(default = "default_real_estate_pct")]
4773    pub real_estate_percent: f64,
4774}
4775
4776fn default_lease_count() -> usize {
4777    50
4778}
4779
4780fn default_finance_lease_pct() -> f64 {
4781    0.30
4782}
4783
4784fn default_avg_lease_term() -> u32 {
4785    60
4786}
4787
4788fn default_real_estate_pct() -> f64 {
4789    0.40
4790}
4791
4792impl Default for LeaseAccountingConfig {
4793    fn default() -> Self {
4794        Self {
4795            enabled: false,
4796            lease_count: default_lease_count(),
4797            finance_lease_percent: default_finance_lease_pct(),
4798            avg_lease_term_months: default_avg_lease_term(),
4799            generate_amortization: true,
4800            real_estate_percent: default_real_estate_pct(),
4801        }
4802    }
4803}
4804
4805/// Fair value measurement configuration (ASC 820/IFRS 13).
4806#[derive(Debug, Clone, Serialize, Deserialize)]
4807pub struct FairValueConfig {
4808    /// Enable fair value measurement generation
4809    #[serde(default)]
4810    pub enabled: bool,
4811
4812    /// Number of fair value measurements to generate
4813    #[serde(default = "default_fv_count")]
4814    pub measurement_count: usize,
4815
4816    /// Level 1 (quoted prices) percentage
4817    #[serde(default = "default_level1_pct")]
4818    pub level1_percent: f64,
4819
4820    /// Level 2 (observable inputs) percentage
4821    #[serde(default = "default_level2_pct")]
4822    pub level2_percent: f64,
4823
4824    /// Level 3 (unobservable inputs) percentage
4825    #[serde(default = "default_level3_pct")]
4826    pub level3_percent: f64,
4827
4828    /// Include sensitivity analysis for Level 3
4829    #[serde(default)]
4830    pub include_sensitivity_analysis: bool,
4831}
4832
4833fn default_fv_count() -> usize {
4834    25
4835}
4836
4837fn default_level1_pct() -> f64 {
4838    0.40
4839}
4840
4841fn default_level2_pct() -> f64 {
4842    0.35
4843}
4844
4845fn default_level3_pct() -> f64 {
4846    0.25
4847}
4848
4849impl Default for FairValueConfig {
4850    fn default() -> Self {
4851        Self {
4852            enabled: false,
4853            measurement_count: default_fv_count(),
4854            level1_percent: default_level1_pct(),
4855            level2_percent: default_level2_pct(),
4856            level3_percent: default_level3_pct(),
4857            include_sensitivity_analysis: false,
4858        }
4859    }
4860}
4861
4862/// Impairment testing configuration (ASC 360/IAS 36).
4863#[derive(Debug, Clone, Serialize, Deserialize)]
4864pub struct ImpairmentConfig {
4865    /// Enable impairment testing generation
4866    #[serde(default)]
4867    pub enabled: bool,
4868
4869    /// Number of impairment tests to generate
4870    #[serde(default = "default_impairment_count")]
4871    pub test_count: usize,
4872
4873    /// Rate of tests resulting in impairment
4874    #[serde(default = "default_impairment_rate")]
4875    pub impairment_rate: f64,
4876
4877    /// Generate cash flow projections
4878    #[serde(default = "default_true")]
4879    pub generate_projections: bool,
4880
4881    /// Include goodwill impairment tests
4882    #[serde(default)]
4883    pub include_goodwill: bool,
4884}
4885
4886fn default_impairment_count() -> usize {
4887    15
4888}
4889
4890fn default_impairment_rate() -> f64 {
4891    0.10
4892}
4893
4894impl Default for ImpairmentConfig {
4895    fn default() -> Self {
4896        Self {
4897            enabled: false,
4898            test_count: default_impairment_count(),
4899            impairment_rate: default_impairment_rate(),
4900            generate_projections: true,
4901            include_goodwill: false,
4902        }
4903    }
4904}
4905
4906// =============================================================================
4907// Audit Standards Configuration
4908// =============================================================================
4909
4910/// Audit standards framework configuration for generating standards-compliant audit data.
4911///
4912/// Supports ISA (International Standards on Auditing) and PCAOB standards:
4913/// - ISA 200-720: Complete coverage of audit standards
4914/// - ISA 520: Analytical Procedures
4915/// - ISA 505: External Confirmations
4916/// - ISA 700/705/706/701: Audit Reports
4917/// - PCAOB AS 2201: ICFR Auditing
4918#[derive(Debug, Clone, Serialize, Deserialize, Default)]
4919pub struct AuditStandardsConfig {
4920    /// Enable audit standards generation
4921    #[serde(default)]
4922    pub enabled: bool,
4923
4924    /// ISA compliance configuration
4925    #[serde(default)]
4926    pub isa_compliance: IsaComplianceConfig,
4927
4928    /// Analytical procedures configuration (ISA 520)
4929    #[serde(default)]
4930    pub analytical_procedures: AnalyticalProceduresConfig,
4931
4932    /// External confirmations configuration (ISA 505)
4933    #[serde(default)]
4934    pub confirmations: ConfirmationsConfig,
4935
4936    /// Audit opinion configuration (ISA 700/705/706/701)
4937    #[serde(default)]
4938    pub opinion: AuditOpinionConfig,
4939
4940    /// Generate complete audit trail with traceability
4941    #[serde(default)]
4942    pub generate_audit_trail: bool,
4943
4944    /// SOX 302/404 compliance configuration
4945    #[serde(default)]
4946    pub sox: SoxComplianceConfig,
4947
4948    /// PCAOB-specific configuration
4949    #[serde(default)]
4950    pub pcaob: PcaobConfig,
4951}
4952
4953/// ISA compliance level configuration.
4954#[derive(Debug, Clone, Serialize, Deserialize)]
4955pub struct IsaComplianceConfig {
4956    /// Enable ISA compliance tracking
4957    #[serde(default)]
4958    pub enabled: bool,
4959
4960    /// Compliance level: "basic", "standard", "comprehensive"
4961    #[serde(default = "default_compliance_level")]
4962    pub compliance_level: String,
4963
4964    /// Generate ISA requirement mappings
4965    #[serde(default = "default_true")]
4966    pub generate_isa_mappings: bool,
4967
4968    /// Generate ISA coverage summary
4969    #[serde(default = "default_true")]
4970    pub generate_coverage_summary: bool,
4971
4972    /// Include PCAOB standard mappings (for dual framework)
4973    #[serde(default)]
4974    pub include_pcaob: bool,
4975
4976    /// Framework to use: "isa", "pcaob", "dual"
4977    #[serde(default = "default_audit_framework")]
4978    pub framework: String,
4979}
4980
4981fn default_compliance_level() -> String {
4982    "standard".to_string()
4983}
4984
4985fn default_audit_framework() -> String {
4986    "isa".to_string()
4987}
4988
4989impl Default for IsaComplianceConfig {
4990    fn default() -> Self {
4991        Self {
4992            enabled: false,
4993            compliance_level: default_compliance_level(),
4994            generate_isa_mappings: true,
4995            generate_coverage_summary: true,
4996            include_pcaob: false,
4997            framework: default_audit_framework(),
4998        }
4999    }
5000}
5001
5002/// Analytical procedures configuration (ISA 520).
5003#[derive(Debug, Clone, Serialize, Deserialize)]
5004pub struct AnalyticalProceduresConfig {
5005    /// Enable analytical procedures generation
5006    #[serde(default)]
5007    pub enabled: bool,
5008
5009    /// Number of procedures per account/area
5010    #[serde(default = "default_procedures_per_account")]
5011    pub procedures_per_account: usize,
5012
5013    /// Probability of variance exceeding threshold
5014    #[serde(default = "default_variance_probability")]
5015    pub variance_probability: f64,
5016
5017    /// Include variance investigations
5018    #[serde(default = "default_true")]
5019    pub generate_investigations: bool,
5020
5021    /// Include financial ratio analysis
5022    #[serde(default = "default_true")]
5023    pub include_ratio_analysis: bool,
5024}
5025
5026fn default_procedures_per_account() -> usize {
5027    3
5028}
5029
5030fn default_variance_probability() -> f64 {
5031    0.20
5032}
5033
5034impl Default for AnalyticalProceduresConfig {
5035    fn default() -> Self {
5036        Self {
5037            enabled: false,
5038            procedures_per_account: default_procedures_per_account(),
5039            variance_probability: default_variance_probability(),
5040            generate_investigations: true,
5041            include_ratio_analysis: true,
5042        }
5043    }
5044}
5045
5046/// External confirmations configuration (ISA 505).
5047#[derive(Debug, Clone, Serialize, Deserialize)]
5048pub struct ConfirmationsConfig {
5049    /// Enable confirmation generation
5050    #[serde(default)]
5051    pub enabled: bool,
5052
5053    /// Number of confirmations to generate
5054    #[serde(default = "default_confirmation_count")]
5055    pub confirmation_count: usize,
5056
5057    /// Positive response rate
5058    #[serde(default = "default_positive_response_rate")]
5059    pub positive_response_rate: f64,
5060
5061    /// Exception rate (responses with differences)
5062    #[serde(default = "default_exception_rate_confirm")]
5063    pub exception_rate: f64,
5064
5065    /// Non-response rate
5066    #[serde(default = "default_non_response_rate")]
5067    pub non_response_rate: f64,
5068
5069    /// Generate alternative procedures for non-responses
5070    #[serde(default = "default_true")]
5071    pub generate_alternative_procedures: bool,
5072}
5073
5074fn default_confirmation_count() -> usize {
5075    50
5076}
5077
5078fn default_positive_response_rate() -> f64 {
5079    0.85
5080}
5081
5082fn default_exception_rate_confirm() -> f64 {
5083    0.10
5084}
5085
5086fn default_non_response_rate() -> f64 {
5087    0.05
5088}
5089
5090impl Default for ConfirmationsConfig {
5091    fn default() -> Self {
5092        Self {
5093            enabled: false,
5094            confirmation_count: default_confirmation_count(),
5095            positive_response_rate: default_positive_response_rate(),
5096            exception_rate: default_exception_rate_confirm(),
5097            non_response_rate: default_non_response_rate(),
5098            generate_alternative_procedures: true,
5099        }
5100    }
5101}
5102
5103/// Audit opinion configuration (ISA 700/705/706/701).
5104#[derive(Debug, Clone, Serialize, Deserialize)]
5105pub struct AuditOpinionConfig {
5106    /// Enable audit opinion generation
5107    #[serde(default)]
5108    pub enabled: bool,
5109
5110    /// Generate Key Audit Matters (KAM) / Critical Audit Matters (CAM)
5111    #[serde(default = "default_true")]
5112    pub generate_kam: bool,
5113
5114    /// Average number of KAMs/CAMs per opinion
5115    #[serde(default = "default_kam_count")]
5116    pub average_kam_count: usize,
5117
5118    /// Rate of modified opinions
5119    #[serde(default = "default_modified_opinion_rate")]
5120    pub modified_opinion_rate: f64,
5121
5122    /// Include emphasis of matter paragraphs
5123    #[serde(default)]
5124    pub include_emphasis_of_matter: bool,
5125
5126    /// Include going concern conclusions
5127    #[serde(default = "default_true")]
5128    pub include_going_concern: bool,
5129}
5130
5131fn default_kam_count() -> usize {
5132    3
5133}
5134
5135fn default_modified_opinion_rate() -> f64 {
5136    0.05
5137}
5138
5139impl Default for AuditOpinionConfig {
5140    fn default() -> Self {
5141        Self {
5142            enabled: false,
5143            generate_kam: true,
5144            average_kam_count: default_kam_count(),
5145            modified_opinion_rate: default_modified_opinion_rate(),
5146            include_emphasis_of_matter: false,
5147            include_going_concern: true,
5148        }
5149    }
5150}
5151
5152/// SOX compliance configuration (Sections 302/404).
5153#[derive(Debug, Clone, Serialize, Deserialize)]
5154pub struct SoxComplianceConfig {
5155    /// Enable SOX compliance generation
5156    #[serde(default)]
5157    pub enabled: bool,
5158
5159    /// Generate Section 302 CEO/CFO certifications
5160    #[serde(default = "default_true")]
5161    pub generate_302_certifications: bool,
5162
5163    /// Generate Section 404 ICFR assessments
5164    #[serde(default = "default_true")]
5165    pub generate_404_assessments: bool,
5166
5167    /// Materiality threshold for SOX testing
5168    #[serde(default = "default_sox_materiality_threshold")]
5169    pub materiality_threshold: f64,
5170
5171    /// Rate of material weaknesses
5172    #[serde(default = "default_material_weakness_rate")]
5173    pub material_weakness_rate: f64,
5174
5175    /// Rate of significant deficiencies
5176    #[serde(default = "default_significant_deficiency_rate")]
5177    pub significant_deficiency_rate: f64,
5178}
5179
5180fn default_material_weakness_rate() -> f64 {
5181    0.02
5182}
5183
5184fn default_significant_deficiency_rate() -> f64 {
5185    0.08
5186}
5187
5188impl Default for SoxComplianceConfig {
5189    fn default() -> Self {
5190        Self {
5191            enabled: false,
5192            generate_302_certifications: true,
5193            generate_404_assessments: true,
5194            materiality_threshold: default_sox_materiality_threshold(),
5195            material_weakness_rate: default_material_weakness_rate(),
5196            significant_deficiency_rate: default_significant_deficiency_rate(),
5197        }
5198    }
5199}
5200
5201/// PCAOB-specific configuration.
5202#[derive(Debug, Clone, Serialize, Deserialize)]
5203pub struct PcaobConfig {
5204    /// Enable PCAOB-specific elements
5205    #[serde(default)]
5206    pub enabled: bool,
5207
5208    /// Treat as PCAOB audit (vs ISA-only)
5209    #[serde(default)]
5210    pub is_pcaob_audit: bool,
5211
5212    /// Generate Critical Audit Matters (CAM)
5213    #[serde(default = "default_true")]
5214    pub generate_cam: bool,
5215
5216    /// Include ICFR opinion (for integrated audits)
5217    #[serde(default)]
5218    pub include_icfr_opinion: bool,
5219
5220    /// Generate PCAOB-ISA standard mappings
5221    #[serde(default)]
5222    pub generate_standard_mappings: bool,
5223}
5224
5225impl Default for PcaobConfig {
5226    fn default() -> Self {
5227        Self {
5228            enabled: false,
5229            is_pcaob_audit: false,
5230            generate_cam: true,
5231            include_icfr_opinion: false,
5232            generate_standard_mappings: false,
5233        }
5234    }
5235}
5236
5237// =============================================================================
5238// Advanced Distribution Configuration
5239// =============================================================================
5240
5241/// Advanced distribution configuration for realistic data generation.
5242///
5243/// This section enables sophisticated distribution models including:
5244/// - Mixture models (multi-modal distributions)
5245/// - Cross-field correlations
5246/// - Conditional distributions
5247/// - Regime changes and economic cycles
5248/// - Statistical validation
5249#[derive(Debug, Clone, Serialize, Deserialize, Default)]
5250pub struct AdvancedDistributionConfig {
5251    /// Enable advanced distribution features.
5252    #[serde(default)]
5253    pub enabled: bool,
5254
5255    /// Mixture model configuration for amounts.
5256    #[serde(default)]
5257    pub amounts: MixtureDistributionSchemaConfig,
5258
5259    /// Cross-field correlation configuration.
5260    #[serde(default)]
5261    pub correlations: CorrelationSchemaConfig,
5262
5263    /// Conditional distribution configurations.
5264    #[serde(default)]
5265    pub conditional: Vec<ConditionalDistributionSchemaConfig>,
5266
5267    /// Regime change configuration.
5268    #[serde(default)]
5269    pub regime_changes: RegimeChangeSchemaConfig,
5270
5271    /// Industry-specific distribution profile.
5272    #[serde(default)]
5273    pub industry_profile: Option<IndustryProfileType>,
5274
5275    /// Statistical validation configuration.
5276    #[serde(default)]
5277    pub validation: StatisticalValidationSchemaConfig,
5278}
5279
5280/// Industry profile types for pre-configured distribution settings.
5281#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5282#[serde(rename_all = "snake_case")]
5283pub enum IndustryProfileType {
5284    /// Retail industry profile (POS sales, inventory, seasonal)
5285    Retail,
5286    /// Manufacturing industry profile (raw materials, maintenance, capital)
5287    Manufacturing,
5288    /// Financial services profile (wire transfers, ACH, fee income)
5289    FinancialServices,
5290    /// Healthcare profile (claims, procedures, supplies)
5291    Healthcare,
5292    /// Technology profile (subscriptions, services, R&D)
5293    Technology,
5294}
5295
5296/// Mixture model distribution configuration.
5297#[derive(Debug, Clone, Serialize, Deserialize)]
5298pub struct MixtureDistributionSchemaConfig {
5299    /// Enable mixture model for amount generation.
5300    #[serde(default)]
5301    pub enabled: bool,
5302
5303    /// Distribution type: "gaussian" or "lognormal".
5304    #[serde(default = "default_mixture_type")]
5305    pub distribution_type: MixtureDistributionType,
5306
5307    /// Mixture components with weights.
5308    #[serde(default)]
5309    pub components: Vec<MixtureComponentConfig>,
5310
5311    /// Minimum value constraint.
5312    #[serde(default = "default_min_amount")]
5313    pub min_value: f64,
5314
5315    /// Maximum value constraint (optional).
5316    #[serde(default)]
5317    pub max_value: Option<f64>,
5318
5319    /// Decimal places for rounding.
5320    #[serde(default = "default_decimal_places")]
5321    pub decimal_places: u8,
5322}
5323
5324fn default_mixture_type() -> MixtureDistributionType {
5325    MixtureDistributionType::LogNormal
5326}
5327
5328fn default_min_amount() -> f64 {
5329    0.01
5330}
5331
5332fn default_decimal_places() -> u8 {
5333    2
5334}
5335
5336impl Default for MixtureDistributionSchemaConfig {
5337    fn default() -> Self {
5338        Self {
5339            enabled: false,
5340            distribution_type: MixtureDistributionType::LogNormal,
5341            components: Vec::new(),
5342            min_value: 0.01,
5343            max_value: None,
5344            decimal_places: 2,
5345        }
5346    }
5347}
5348
5349/// Mixture distribution type.
5350#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
5351#[serde(rename_all = "snake_case")]
5352pub enum MixtureDistributionType {
5353    /// Gaussian (normal) mixture
5354    Gaussian,
5355    /// Log-normal mixture (for positive amounts)
5356    #[default]
5357    LogNormal,
5358}
5359
5360/// Configuration for a single mixture component.
5361#[derive(Debug, Clone, Serialize, Deserialize)]
5362pub struct MixtureComponentConfig {
5363    /// Weight of this component (must sum to 1.0 across all components).
5364    pub weight: f64,
5365
5366    /// Location parameter (mean for Gaussian, mu for log-normal).
5367    pub mu: f64,
5368
5369    /// Scale parameter (std dev for Gaussian, sigma for log-normal).
5370    pub sigma: f64,
5371
5372    /// Optional label for this component (e.g., "routine", "significant", "major").
5373    #[serde(default)]
5374    pub label: Option<String>,
5375}
5376
5377/// Cross-field correlation configuration.
5378#[derive(Debug, Clone, Serialize, Deserialize)]
5379pub struct CorrelationSchemaConfig {
5380    /// Enable correlation modeling.
5381    #[serde(default)]
5382    pub enabled: bool,
5383
5384    /// Copula type for dependency modeling.
5385    #[serde(default)]
5386    pub copula_type: CopulaSchemaType,
5387
5388    /// Field definitions for correlation.
5389    #[serde(default)]
5390    pub fields: Vec<CorrelatedFieldConfig>,
5391
5392    /// Correlation matrix (upper triangular, row-major).
5393    /// For n fields, this should have n*(n-1)/2 values.
5394    #[serde(default)]
5395    pub matrix: Vec<f64>,
5396
5397    /// Expected correlations for validation.
5398    #[serde(default)]
5399    pub expected_correlations: Vec<ExpectedCorrelationConfig>,
5400}
5401
5402impl Default for CorrelationSchemaConfig {
5403    fn default() -> Self {
5404        Self {
5405            enabled: false,
5406            copula_type: CopulaSchemaType::Gaussian,
5407            fields: Vec::new(),
5408            matrix: Vec::new(),
5409            expected_correlations: Vec::new(),
5410        }
5411    }
5412}
5413
5414/// Copula type for dependency modeling.
5415#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
5416#[serde(rename_all = "snake_case")]
5417pub enum CopulaSchemaType {
5418    /// Gaussian copula (symmetric, no tail dependence)
5419    #[default]
5420    Gaussian,
5421    /// Clayton copula (lower tail dependence)
5422    Clayton,
5423    /// Gumbel copula (upper tail dependence)
5424    Gumbel,
5425    /// Frank copula (symmetric, no tail dependence)
5426    Frank,
5427    /// Student-t copula (both tail dependencies)
5428    StudentT,
5429}
5430
5431/// Configuration for a correlated field.
5432#[derive(Debug, Clone, Serialize, Deserialize)]
5433pub struct CorrelatedFieldConfig {
5434    /// Field name.
5435    pub name: String,
5436
5437    /// Marginal distribution type.
5438    #[serde(default)]
5439    pub distribution: MarginalDistributionConfig,
5440}
5441
5442/// Marginal distribution configuration.
5443#[derive(Debug, Clone, Serialize, Deserialize)]
5444#[serde(tag = "type", rename_all = "snake_case")]
5445pub enum MarginalDistributionConfig {
5446    /// Normal distribution.
5447    Normal {
5448        /// Mean
5449        mu: f64,
5450        /// Standard deviation
5451        sigma: f64,
5452    },
5453    /// Log-normal distribution.
5454    LogNormal {
5455        /// Location parameter
5456        mu: f64,
5457        /// Scale parameter
5458        sigma: f64,
5459    },
5460    /// Uniform distribution.
5461    Uniform {
5462        /// Minimum value
5463        min: f64,
5464        /// Maximum value
5465        max: f64,
5466    },
5467    /// Discrete uniform distribution.
5468    DiscreteUniform {
5469        /// Minimum integer value
5470        min: i32,
5471        /// Maximum integer value
5472        max: i32,
5473    },
5474}
5475
5476impl Default for MarginalDistributionConfig {
5477    fn default() -> Self {
5478        Self::Normal {
5479            mu: 0.0,
5480            sigma: 1.0,
5481        }
5482    }
5483}
5484
5485/// Expected correlation for validation.
5486#[derive(Debug, Clone, Serialize, Deserialize)]
5487pub struct ExpectedCorrelationConfig {
5488    /// First field name.
5489    pub field1: String,
5490    /// Second field name.
5491    pub field2: String,
5492    /// Expected correlation coefficient.
5493    pub expected_r: f64,
5494    /// Acceptable tolerance.
5495    #[serde(default = "default_correlation_tolerance")]
5496    pub tolerance: f64,
5497}
5498
5499fn default_correlation_tolerance() -> f64 {
5500    0.10
5501}
5502
5503/// Conditional distribution configuration.
5504#[derive(Debug, Clone, Serialize, Deserialize)]
5505pub struct ConditionalDistributionSchemaConfig {
5506    /// Output field name to generate.
5507    pub output_field: String,
5508
5509    /// Input field name that conditions the distribution.
5510    pub input_field: String,
5511
5512    /// Breakpoints defining distribution changes.
5513    #[serde(default)]
5514    pub breakpoints: Vec<ConditionalBreakpointConfig>,
5515
5516    /// Default distribution when below all breakpoints.
5517    #[serde(default)]
5518    pub default_distribution: ConditionalDistributionParamsConfig,
5519
5520    /// Minimum output value constraint.
5521    #[serde(default)]
5522    pub min_value: Option<f64>,
5523
5524    /// Maximum output value constraint.
5525    #[serde(default)]
5526    pub max_value: Option<f64>,
5527
5528    /// Decimal places for output rounding.
5529    #[serde(default = "default_decimal_places")]
5530    pub decimal_places: u8,
5531}
5532
5533/// Breakpoint for conditional distribution.
5534#[derive(Debug, Clone, Serialize, Deserialize)]
5535pub struct ConditionalBreakpointConfig {
5536    /// Input value threshold.
5537    pub threshold: f64,
5538
5539    /// Distribution to use when input >= threshold.
5540    pub distribution: ConditionalDistributionParamsConfig,
5541}
5542
5543/// Distribution parameters for conditional distributions.
5544#[derive(Debug, Clone, Serialize, Deserialize)]
5545#[serde(tag = "type", rename_all = "snake_case")]
5546pub enum ConditionalDistributionParamsConfig {
5547    /// Fixed value.
5548    Fixed {
5549        /// The fixed value
5550        value: f64,
5551    },
5552    /// Normal distribution.
5553    Normal {
5554        /// Mean
5555        mu: f64,
5556        /// Standard deviation
5557        sigma: f64,
5558    },
5559    /// Log-normal distribution.
5560    LogNormal {
5561        /// Location parameter
5562        mu: f64,
5563        /// Scale parameter
5564        sigma: f64,
5565    },
5566    /// Uniform distribution.
5567    Uniform {
5568        /// Minimum
5569        min: f64,
5570        /// Maximum
5571        max: f64,
5572    },
5573    /// Beta distribution (scaled).
5574    Beta {
5575        /// Alpha parameter
5576        alpha: f64,
5577        /// Beta parameter
5578        beta: f64,
5579        /// Minimum output value
5580        min: f64,
5581        /// Maximum output value
5582        max: f64,
5583    },
5584    /// Discrete values with weights.
5585    Discrete {
5586        /// Possible values
5587        values: Vec<f64>,
5588        /// Weights (should sum to 1.0)
5589        weights: Vec<f64>,
5590    },
5591}
5592
5593impl Default for ConditionalDistributionParamsConfig {
5594    fn default() -> Self {
5595        Self::Normal {
5596            mu: 0.0,
5597            sigma: 1.0,
5598        }
5599    }
5600}
5601
5602/// Regime change configuration.
5603#[derive(Debug, Clone, Serialize, Deserialize, Default)]
5604pub struct RegimeChangeSchemaConfig {
5605    /// Enable regime change modeling.
5606    #[serde(default)]
5607    pub enabled: bool,
5608
5609    /// List of regime changes.
5610    #[serde(default)]
5611    pub changes: Vec<RegimeChangeEventConfig>,
5612
5613    /// Economic cycle configuration.
5614    #[serde(default)]
5615    pub economic_cycle: Option<EconomicCycleSchemaConfig>,
5616
5617    /// Parameter drift configurations.
5618    #[serde(default)]
5619    pub parameter_drifts: Vec<ParameterDriftSchemaConfig>,
5620}
5621
5622/// A single regime change event.
5623#[derive(Debug, Clone, Serialize, Deserialize)]
5624pub struct RegimeChangeEventConfig {
5625    /// Date when the change occurs (ISO 8601 format).
5626    pub date: String,
5627
5628    /// Type of regime change.
5629    pub change_type: RegimeChangeTypeConfig,
5630
5631    /// Description of the change.
5632    #[serde(default)]
5633    pub description: Option<String>,
5634
5635    /// Effects of this regime change.
5636    #[serde(default)]
5637    pub effects: Vec<RegimeEffectConfig>,
5638}
5639
5640/// Type of regime change.
5641#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5642#[serde(rename_all = "snake_case")]
5643pub enum RegimeChangeTypeConfig {
5644    /// Acquisition - sudden volume and amount increase
5645    Acquisition,
5646    /// Divestiture - sudden volume and amount decrease
5647    Divestiture,
5648    /// Price increase - amounts increase
5649    PriceIncrease,
5650    /// Price decrease - amounts decrease
5651    PriceDecrease,
5652    /// New product launch - volume ramp-up
5653    ProductLaunch,
5654    /// Product discontinuation - volume ramp-down
5655    ProductDiscontinuation,
5656    /// Policy change - affects patterns
5657    PolicyChange,
5658    /// Competitor entry - market disruption
5659    CompetitorEntry,
5660    /// Custom effect
5661    Custom,
5662}
5663
5664/// Effect of a regime change on a specific field.
5665#[derive(Debug, Clone, Serialize, Deserialize)]
5666pub struct RegimeEffectConfig {
5667    /// Field being affected.
5668    pub field: String,
5669
5670    /// Multiplier to apply (1.0 = no change, 1.5 = 50% increase).
5671    pub multiplier: f64,
5672}
5673
5674/// Economic cycle configuration.
5675#[derive(Debug, Clone, Serialize, Deserialize)]
5676pub struct EconomicCycleSchemaConfig {
5677    /// Enable economic cycle modeling.
5678    #[serde(default)]
5679    pub enabled: bool,
5680
5681    /// Cycle period in months (e.g., 48 for 4-year business cycle).
5682    #[serde(default = "default_cycle_period")]
5683    pub period_months: u32,
5684
5685    /// Amplitude of cycle effect (0.0-1.0).
5686    #[serde(default = "default_cycle_amplitude")]
5687    pub amplitude: f64,
5688
5689    /// Phase offset in months.
5690    #[serde(default)]
5691    pub phase_offset: u32,
5692
5693    /// Recession periods (start_month, duration_months).
5694    #[serde(default)]
5695    pub recessions: Vec<RecessionPeriodConfig>,
5696}
5697
5698fn default_cycle_period() -> u32 {
5699    48
5700}
5701
5702fn default_cycle_amplitude() -> f64 {
5703    0.15
5704}
5705
5706impl Default for EconomicCycleSchemaConfig {
5707    fn default() -> Self {
5708        Self {
5709            enabled: false,
5710            period_months: 48,
5711            amplitude: 0.15,
5712            phase_offset: 0,
5713            recessions: Vec::new(),
5714        }
5715    }
5716}
5717
5718/// Recession period configuration.
5719#[derive(Debug, Clone, Serialize, Deserialize)]
5720pub struct RecessionPeriodConfig {
5721    /// Start month (0-indexed from generation start).
5722    pub start_month: u32,
5723
5724    /// Duration in months.
5725    pub duration_months: u32,
5726
5727    /// Severity (0.0-1.0, affects volume reduction).
5728    #[serde(default = "default_recession_severity")]
5729    pub severity: f64,
5730}
5731
5732fn default_recession_severity() -> f64 {
5733    0.20
5734}
5735
5736/// Parameter drift configuration.
5737#[derive(Debug, Clone, Serialize, Deserialize)]
5738pub struct ParameterDriftSchemaConfig {
5739    /// Parameter being drifted.
5740    pub parameter: String,
5741
5742    /// Drift type.
5743    pub drift_type: ParameterDriftTypeConfig,
5744
5745    /// Start value.
5746    pub start_value: f64,
5747
5748    /// End value.
5749    pub end_value: f64,
5750
5751    /// Start period (month, 0-indexed).
5752    #[serde(default)]
5753    pub start_period: u32,
5754
5755    /// End period (month, optional - defaults to end of generation).
5756    #[serde(default)]
5757    pub end_period: Option<u32>,
5758}
5759
5760/// Parameter drift type.
5761#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
5762#[serde(rename_all = "snake_case")]
5763pub enum ParameterDriftTypeConfig {
5764    /// Linear interpolation
5765    #[default]
5766    Linear,
5767    /// Exponential growth/decay
5768    Exponential,
5769    /// S-curve (logistic)
5770    Logistic,
5771    /// Step function
5772    Step,
5773}
5774
5775/// Statistical validation configuration.
5776#[derive(Debug, Clone, Serialize, Deserialize, Default)]
5777pub struct StatisticalValidationSchemaConfig {
5778    /// Enable statistical validation.
5779    #[serde(default)]
5780    pub enabled: bool,
5781
5782    /// Statistical tests to run.
5783    #[serde(default)]
5784    pub tests: Vec<StatisticalTestConfig>,
5785
5786    /// Validation reporting configuration.
5787    #[serde(default)]
5788    pub reporting: ValidationReportingConfig,
5789}
5790
5791/// Statistical test configuration.
5792#[derive(Debug, Clone, Serialize, Deserialize)]
5793#[serde(tag = "type", rename_all = "snake_case")]
5794pub enum StatisticalTestConfig {
5795    /// Benford's Law first digit test.
5796    BenfordFirstDigit {
5797        /// Threshold MAD for failure.
5798        #[serde(default = "default_benford_threshold")]
5799        threshold_mad: f64,
5800        /// Warning MAD threshold.
5801        #[serde(default = "default_benford_warning")]
5802        warning_mad: f64,
5803    },
5804    /// Distribution fit test.
5805    DistributionFit {
5806        /// Target distribution to test.
5807        target: TargetDistributionConfig,
5808        /// K-S test significance level.
5809        #[serde(default = "default_ks_significance")]
5810        ks_significance: f64,
5811        /// Test method (ks, anderson_darling, chi_squared).
5812        #[serde(default)]
5813        method: DistributionFitMethod,
5814    },
5815    /// Correlation check.
5816    CorrelationCheck {
5817        /// Expected correlations to validate.
5818        expected_correlations: Vec<ExpectedCorrelationConfig>,
5819    },
5820    /// Chi-squared test.
5821    ChiSquared {
5822        /// Number of bins.
5823        #[serde(default = "default_chi_squared_bins")]
5824        bins: usize,
5825        /// Significance level.
5826        #[serde(default = "default_chi_squared_significance")]
5827        significance: f64,
5828    },
5829    /// Anderson-Darling test.
5830    AndersonDarling {
5831        /// Target distribution.
5832        target: TargetDistributionConfig,
5833        /// Significance level.
5834        #[serde(default = "default_ad_significance")]
5835        significance: f64,
5836    },
5837}
5838
5839fn default_benford_threshold() -> f64 {
5840    0.015
5841}
5842
5843fn default_benford_warning() -> f64 {
5844    0.010
5845}
5846
5847fn default_ks_significance() -> f64 {
5848    0.05
5849}
5850
5851fn default_chi_squared_bins() -> usize {
5852    10
5853}
5854
5855fn default_chi_squared_significance() -> f64 {
5856    0.05
5857}
5858
5859fn default_ad_significance() -> f64 {
5860    0.05
5861}
5862
5863/// Target distribution for fit tests.
5864#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
5865#[serde(rename_all = "snake_case")]
5866pub enum TargetDistributionConfig {
5867    /// Normal distribution
5868    Normal,
5869    /// Log-normal distribution
5870    #[default]
5871    LogNormal,
5872    /// Exponential distribution
5873    Exponential,
5874    /// Uniform distribution
5875    Uniform,
5876}
5877
5878/// Distribution fit test method.
5879#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
5880#[serde(rename_all = "snake_case")]
5881pub enum DistributionFitMethod {
5882    /// Kolmogorov-Smirnov test
5883    #[default]
5884    KolmogorovSmirnov,
5885    /// Anderson-Darling test
5886    AndersonDarling,
5887    /// Chi-squared test
5888    ChiSquared,
5889}
5890
5891/// Validation reporting configuration.
5892#[derive(Debug, Clone, Serialize, Deserialize)]
5893pub struct ValidationReportingConfig {
5894    /// Output validation report to file.
5895    #[serde(default)]
5896    pub output_report: bool,
5897
5898    /// Report format.
5899    #[serde(default)]
5900    pub format: ValidationReportFormat,
5901
5902    /// Fail generation if validation fails.
5903    #[serde(default)]
5904    pub fail_on_error: bool,
5905
5906    /// Include detailed statistics in report.
5907    #[serde(default = "default_true")]
5908    pub include_details: bool,
5909}
5910
5911impl Default for ValidationReportingConfig {
5912    fn default() -> Self {
5913        Self {
5914            output_report: false,
5915            format: ValidationReportFormat::Json,
5916            fail_on_error: false,
5917            include_details: true,
5918        }
5919    }
5920}
5921
5922/// Validation report format.
5923#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
5924#[serde(rename_all = "snake_case")]
5925pub enum ValidationReportFormat {
5926    /// JSON format
5927    #[default]
5928    Json,
5929    /// YAML format
5930    Yaml,
5931    /// HTML report
5932    Html,
5933}
5934
5935// =============================================================================
5936// Temporal Patterns Configuration
5937// =============================================================================
5938
5939/// Temporal patterns configuration for business days, period-end dynamics, and processing lags.
5940///
5941/// This section enables sophisticated temporal modeling including:
5942/// - Business day calculations and settlement dates
5943/// - Regional holiday calendars
5944/// - Period-end decay curves (non-flat volume spikes)
5945/// - Processing lag modeling (event-to-posting delays)
5946#[derive(Debug, Clone, Serialize, Deserialize, Default)]
5947pub struct TemporalPatternsConfig {
5948    /// Enable temporal patterns features.
5949    #[serde(default)]
5950    pub enabled: bool,
5951
5952    /// Business day calculation configuration.
5953    #[serde(default)]
5954    pub business_days: BusinessDaySchemaConfig,
5955
5956    /// Regional calendar configuration.
5957    #[serde(default)]
5958    pub calendars: CalendarSchemaConfig,
5959
5960    /// Period-end dynamics configuration.
5961    #[serde(default)]
5962    pub period_end: PeriodEndSchemaConfig,
5963
5964    /// Processing lag configuration.
5965    #[serde(default)]
5966    pub processing_lags: ProcessingLagSchemaConfig,
5967
5968    /// Fiscal calendar configuration (custom year start, 4-4-5, 13-period).
5969    #[serde(default)]
5970    pub fiscal_calendar: FiscalCalendarSchemaConfig,
5971
5972    /// Intra-day patterns configuration (morning spike, lunch dip, EOD rush).
5973    #[serde(default)]
5974    pub intraday: IntraDaySchemaConfig,
5975
5976    /// Timezone handling configuration.
5977    #[serde(default)]
5978    pub timezones: TimezoneSchemaConfig,
5979}
5980
5981/// Business day calculation configuration.
5982#[derive(Debug, Clone, Serialize, Deserialize)]
5983pub struct BusinessDaySchemaConfig {
5984    /// Enable business day calculations.
5985    #[serde(default = "default_true")]
5986    pub enabled: bool,
5987
5988    /// Half-day policy: "full_day", "half_day", "non_business_day".
5989    #[serde(default = "default_half_day_policy")]
5990    pub half_day_policy: String,
5991
5992    /// Settlement rules configuration.
5993    #[serde(default)]
5994    pub settlement_rules: SettlementRulesSchemaConfig,
5995
5996    /// Month-end convention: "modified_following", "preceding", "following", "end_of_month".
5997    #[serde(default = "default_month_end_convention")]
5998    pub month_end_convention: String,
5999
6000    /// Weekend days (e.g., ["saturday", "sunday"] or ["friday", "saturday"] for Middle East).
6001    #[serde(default)]
6002    pub weekend_days: Option<Vec<String>>,
6003}
6004
6005fn default_half_day_policy() -> String {
6006    "half_day".to_string()
6007}
6008
6009fn default_month_end_convention() -> String {
6010    "modified_following".to_string()
6011}
6012
6013impl Default for BusinessDaySchemaConfig {
6014    fn default() -> Self {
6015        Self {
6016            enabled: true,
6017            half_day_policy: "half_day".to_string(),
6018            settlement_rules: SettlementRulesSchemaConfig::default(),
6019            month_end_convention: "modified_following".to_string(),
6020            weekend_days: None,
6021        }
6022    }
6023}
6024
6025/// Settlement rules configuration.
6026#[derive(Debug, Clone, Serialize, Deserialize)]
6027pub struct SettlementRulesSchemaConfig {
6028    /// Equity settlement days (T+N).
6029    #[serde(default = "default_settlement_2")]
6030    pub equity_days: i32,
6031
6032    /// Government bonds settlement days.
6033    #[serde(default = "default_settlement_1")]
6034    pub government_bonds_days: i32,
6035
6036    /// FX spot settlement days.
6037    #[serde(default = "default_settlement_2")]
6038    pub fx_spot_days: i32,
6039
6040    /// Corporate bonds settlement days.
6041    #[serde(default = "default_settlement_2")]
6042    pub corporate_bonds_days: i32,
6043
6044    /// Wire transfer cutoff time (HH:MM format).
6045    #[serde(default = "default_wire_cutoff")]
6046    pub wire_cutoff_time: String,
6047
6048    /// International wire settlement days.
6049    #[serde(default = "default_settlement_1")]
6050    pub wire_international_days: i32,
6051
6052    /// ACH settlement days.
6053    #[serde(default = "default_settlement_1")]
6054    pub ach_days: i32,
6055}
6056
6057fn default_settlement_1() -> i32 {
6058    1
6059}
6060
6061fn default_settlement_2() -> i32 {
6062    2
6063}
6064
6065fn default_wire_cutoff() -> String {
6066    "14:00".to_string()
6067}
6068
6069impl Default for SettlementRulesSchemaConfig {
6070    fn default() -> Self {
6071        Self {
6072            equity_days: 2,
6073            government_bonds_days: 1,
6074            fx_spot_days: 2,
6075            corporate_bonds_days: 2,
6076            wire_cutoff_time: "14:00".to_string(),
6077            wire_international_days: 1,
6078            ach_days: 1,
6079        }
6080    }
6081}
6082
6083/// Regional calendar configuration.
6084#[derive(Debug, Clone, Serialize, Deserialize, Default)]
6085pub struct CalendarSchemaConfig {
6086    /// List of regions to include (e.g., ["US", "DE", "BR", "SG", "KR"]).
6087    #[serde(default)]
6088    pub regions: Vec<String>,
6089
6090    /// Custom holidays (in addition to regional calendars).
6091    #[serde(default)]
6092    pub custom_holidays: Vec<CustomHolidaySchemaConfig>,
6093}
6094
6095/// Custom holiday configuration.
6096#[derive(Debug, Clone, Serialize, Deserialize)]
6097pub struct CustomHolidaySchemaConfig {
6098    /// Holiday name.
6099    pub name: String,
6100    /// Month (1-12).
6101    pub month: u8,
6102    /// Day of month.
6103    pub day: u8,
6104    /// Activity multiplier (0.0-1.0, default 0.05).
6105    #[serde(default = "default_holiday_multiplier")]
6106    pub activity_multiplier: f64,
6107}
6108
6109fn default_holiday_multiplier() -> f64 {
6110    0.05
6111}
6112
6113/// Period-end dynamics configuration.
6114#[derive(Debug, Clone, Serialize, Deserialize, Default)]
6115pub struct PeriodEndSchemaConfig {
6116    /// Model type: "flat", "exponential", "extended_crunch", "daily_profile".
6117    #[serde(default)]
6118    pub model: Option<String>,
6119
6120    /// Month-end configuration.
6121    #[serde(default)]
6122    pub month_end: Option<PeriodEndModelSchemaConfig>,
6123
6124    /// Quarter-end configuration.
6125    #[serde(default)]
6126    pub quarter_end: Option<PeriodEndModelSchemaConfig>,
6127
6128    /// Year-end configuration.
6129    #[serde(default)]
6130    pub year_end: Option<PeriodEndModelSchemaConfig>,
6131}
6132
6133/// Period-end model configuration.
6134#[derive(Debug, Clone, Serialize, Deserialize, Default)]
6135pub struct PeriodEndModelSchemaConfig {
6136    /// Inherit configuration from another period (e.g., "month_end").
6137    #[serde(default)]
6138    pub inherit_from: Option<String>,
6139
6140    /// Additional multiplier on top of inherited/base model.
6141    #[serde(default)]
6142    pub additional_multiplier: Option<f64>,
6143
6144    /// Days before period end to start acceleration (negative, e.g., -10).
6145    #[serde(default)]
6146    pub start_day: Option<i32>,
6147
6148    /// Base multiplier at start of acceleration.
6149    #[serde(default)]
6150    pub base_multiplier: Option<f64>,
6151
6152    /// Peak multiplier on last day.
6153    #[serde(default)]
6154    pub peak_multiplier: Option<f64>,
6155
6156    /// Decay rate for exponential model (0.1-0.5 typical).
6157    #[serde(default)]
6158    pub decay_rate: Option<f64>,
6159
6160    /// Sustained high days for crunch model.
6161    #[serde(default)]
6162    pub sustained_high_days: Option<i32>,
6163}
6164
6165/// Processing lag configuration.
6166#[derive(Debug, Clone, Serialize, Deserialize)]
6167pub struct ProcessingLagSchemaConfig {
6168    /// Enable processing lag calculations.
6169    #[serde(default = "default_true")]
6170    pub enabled: bool,
6171
6172    /// Sales order lag configuration (log-normal mu, sigma).
6173    #[serde(default)]
6174    pub sales_order_lag: Option<LagDistributionSchemaConfig>,
6175
6176    /// Purchase order lag configuration.
6177    #[serde(default)]
6178    pub purchase_order_lag: Option<LagDistributionSchemaConfig>,
6179
6180    /// Goods receipt lag configuration.
6181    #[serde(default)]
6182    pub goods_receipt_lag: Option<LagDistributionSchemaConfig>,
6183
6184    /// Invoice receipt lag configuration.
6185    #[serde(default)]
6186    pub invoice_receipt_lag: Option<LagDistributionSchemaConfig>,
6187
6188    /// Invoice issue lag configuration.
6189    #[serde(default)]
6190    pub invoice_issue_lag: Option<LagDistributionSchemaConfig>,
6191
6192    /// Payment lag configuration.
6193    #[serde(default)]
6194    pub payment_lag: Option<LagDistributionSchemaConfig>,
6195
6196    /// Journal entry lag configuration.
6197    #[serde(default)]
6198    pub journal_entry_lag: Option<LagDistributionSchemaConfig>,
6199
6200    /// Cross-day posting configuration.
6201    #[serde(default)]
6202    pub cross_day_posting: Option<CrossDayPostingSchemaConfig>,
6203}
6204
6205impl Default for ProcessingLagSchemaConfig {
6206    fn default() -> Self {
6207        Self {
6208            enabled: true,
6209            sales_order_lag: None,
6210            purchase_order_lag: None,
6211            goods_receipt_lag: None,
6212            invoice_receipt_lag: None,
6213            invoice_issue_lag: None,
6214            payment_lag: None,
6215            journal_entry_lag: None,
6216            cross_day_posting: None,
6217        }
6218    }
6219}
6220
6221/// Lag distribution configuration (log-normal parameters).
6222#[derive(Debug, Clone, Serialize, Deserialize)]
6223pub struct LagDistributionSchemaConfig {
6224    /// Log-scale mean (mu for log-normal).
6225    pub mu: f64,
6226    /// Log-scale standard deviation (sigma for log-normal).
6227    pub sigma: f64,
6228    /// Minimum lag in hours.
6229    #[serde(default)]
6230    pub min_hours: Option<f64>,
6231    /// Maximum lag in hours.
6232    #[serde(default)]
6233    pub max_hours: Option<f64>,
6234}
6235
6236/// Cross-day posting configuration.
6237#[derive(Debug, Clone, Serialize, Deserialize)]
6238pub struct CrossDayPostingSchemaConfig {
6239    /// Enable cross-day posting logic.
6240    #[serde(default = "default_true")]
6241    pub enabled: bool,
6242
6243    /// Probability of next-day posting by hour (map of hour -> probability).
6244    /// E.g., { 17: 0.7, 19: 0.9, 21: 0.99 }
6245    #[serde(default)]
6246    pub probability_by_hour: std::collections::HashMap<u8, f64>,
6247}
6248
6249impl Default for CrossDayPostingSchemaConfig {
6250    fn default() -> Self {
6251        let mut probability_by_hour = std::collections::HashMap::new();
6252        probability_by_hour.insert(17, 0.3);
6253        probability_by_hour.insert(18, 0.6);
6254        probability_by_hour.insert(19, 0.8);
6255        probability_by_hour.insert(20, 0.9);
6256        probability_by_hour.insert(21, 0.95);
6257        probability_by_hour.insert(22, 0.99);
6258
6259        Self {
6260            enabled: true,
6261            probability_by_hour,
6262        }
6263    }
6264}
6265
6266// =============================================================================
6267// Fiscal Calendar Configuration (P2)
6268// =============================================================================
6269
6270/// Fiscal calendar configuration.
6271///
6272/// Supports calendar year, custom year start, 4-4-5 retail calendar,
6273/// and 13-period calendars.
6274#[derive(Debug, Clone, Serialize, Deserialize, Default)]
6275pub struct FiscalCalendarSchemaConfig {
6276    /// Enable non-standard fiscal calendar.
6277    #[serde(default)]
6278    pub enabled: bool,
6279
6280    /// Fiscal calendar type: "calendar_year", "custom", "four_four_five", "thirteen_period".
6281    #[serde(default = "default_fiscal_calendar_type")]
6282    pub calendar_type: String,
6283
6284    /// Month the fiscal year starts (1-12). Used for custom year start.
6285    #[serde(default)]
6286    pub year_start_month: Option<u8>,
6287
6288    /// Day the fiscal year starts (1-31). Used for custom year start.
6289    #[serde(default)]
6290    pub year_start_day: Option<u8>,
6291
6292    /// 4-4-5 calendar configuration (if calendar_type is "four_four_five").
6293    #[serde(default)]
6294    pub four_four_five: Option<FourFourFiveSchemaConfig>,
6295}
6296
6297fn default_fiscal_calendar_type() -> String {
6298    "calendar_year".to_string()
6299}
6300
6301/// 4-4-5 retail calendar configuration.
6302#[derive(Debug, Clone, Serialize, Deserialize)]
6303pub struct FourFourFiveSchemaConfig {
6304    /// Week pattern: "four_four_five", "four_five_four", "five_four_four".
6305    #[serde(default = "default_week_pattern")]
6306    pub pattern: String,
6307
6308    /// Anchor type: "first_sunday", "last_saturday", "nearest_saturday".
6309    #[serde(default = "default_anchor_type")]
6310    pub anchor_type: String,
6311
6312    /// Anchor month (1-12).
6313    #[serde(default = "default_anchor_month")]
6314    pub anchor_month: u8,
6315
6316    /// Where to place leap week: "q4_period3" or "q1_period1".
6317    #[serde(default = "default_leap_week_placement")]
6318    pub leap_week_placement: String,
6319}
6320
6321fn default_week_pattern() -> String {
6322    "four_four_five".to_string()
6323}
6324
6325fn default_anchor_type() -> String {
6326    "last_saturday".to_string()
6327}
6328
6329fn default_anchor_month() -> u8 {
6330    1 // January
6331}
6332
6333fn default_leap_week_placement() -> String {
6334    "q4_period3".to_string()
6335}
6336
6337impl Default for FourFourFiveSchemaConfig {
6338    fn default() -> Self {
6339        Self {
6340            pattern: "four_four_five".to_string(),
6341            anchor_type: "last_saturday".to_string(),
6342            anchor_month: 1,
6343            leap_week_placement: "q4_period3".to_string(),
6344        }
6345    }
6346}
6347
6348// =============================================================================
6349// Intra-Day Patterns Configuration (P2)
6350// =============================================================================
6351
6352/// Intra-day patterns configuration.
6353///
6354/// Defines time-of-day segments with different activity multipliers
6355/// for realistic modeling of morning spikes, lunch dips, and end-of-day rushes.
6356#[derive(Debug, Clone, Serialize, Deserialize, Default)]
6357pub struct IntraDaySchemaConfig {
6358    /// Enable intra-day patterns.
6359    #[serde(default)]
6360    pub enabled: bool,
6361
6362    /// Custom intra-day segments.
6363    #[serde(default)]
6364    pub segments: Vec<IntraDaySegmentSchemaConfig>,
6365}
6366
6367/// Intra-day segment configuration.
6368#[derive(Debug, Clone, Serialize, Deserialize)]
6369pub struct IntraDaySegmentSchemaConfig {
6370    /// Name of the segment (e.g., "morning_spike", "lunch_dip").
6371    pub name: String,
6372
6373    /// Start time (HH:MM format).
6374    pub start: String,
6375
6376    /// End time (HH:MM format).
6377    pub end: String,
6378
6379    /// Activity multiplier (1.0 = normal).
6380    #[serde(default = "default_multiplier")]
6381    pub multiplier: f64,
6382
6383    /// Posting type: "human", "system", "both".
6384    #[serde(default = "default_posting_type")]
6385    pub posting_type: String,
6386}
6387
6388fn default_multiplier() -> f64 {
6389    1.0
6390}
6391
6392fn default_posting_type() -> String {
6393    "both".to_string()
6394}
6395
6396// =============================================================================
6397// Timezone Configuration
6398// =============================================================================
6399
6400/// Timezone handling configuration for multi-region entities.
6401#[derive(Debug, Clone, Serialize, Deserialize, Default)]
6402pub struct TimezoneSchemaConfig {
6403    /// Enable timezone handling.
6404    #[serde(default)]
6405    pub enabled: bool,
6406
6407    /// Default timezone (IANA format, e.g., "America/New_York").
6408    #[serde(default = "default_timezone")]
6409    pub default_timezone: String,
6410
6411    /// Consolidation timezone for group reporting (IANA format).
6412    #[serde(default = "default_consolidation_timezone")]
6413    pub consolidation_timezone: String,
6414
6415    /// Entity-to-timezone mappings.
6416    /// Supports patterns like "EU_*" -> "Europe/London".
6417    #[serde(default)]
6418    pub entity_mappings: Vec<EntityTimezoneMapping>,
6419}
6420
6421fn default_timezone() -> String {
6422    "America/New_York".to_string()
6423}
6424
6425fn default_consolidation_timezone() -> String {
6426    "UTC".to_string()
6427}
6428
6429/// Mapping from entity pattern to timezone.
6430#[derive(Debug, Clone, Serialize, Deserialize)]
6431pub struct EntityTimezoneMapping {
6432    /// Entity code pattern (e.g., "EU_*", "*_APAC", "1000").
6433    pub pattern: String,
6434
6435    /// Timezone (IANA format, e.g., "Europe/London").
6436    pub timezone: String,
6437}
6438
6439// =============================================================================
6440// Vendor Network Configuration
6441// =============================================================================
6442
6443/// Configuration for multi-tier vendor network generation.
6444#[derive(Debug, Clone, Serialize, Deserialize)]
6445pub struct VendorNetworkSchemaConfig {
6446    /// Enable vendor network generation.
6447    #[serde(default)]
6448    pub enabled: bool,
6449
6450    /// Maximum depth of supply chain tiers (1-3).
6451    #[serde(default = "default_vendor_tier_depth")]
6452    pub depth: u8,
6453
6454    /// Tier 1 vendor count configuration.
6455    #[serde(default)]
6456    pub tier1: TierCountSchemaConfig,
6457
6458    /// Tier 2 vendors per Tier 1 parent.
6459    #[serde(default)]
6460    pub tier2_per_parent: TierCountSchemaConfig,
6461
6462    /// Tier 3 vendors per Tier 2 parent.
6463    #[serde(default)]
6464    pub tier3_per_parent: TierCountSchemaConfig,
6465
6466    /// Vendor cluster distribution.
6467    #[serde(default)]
6468    pub clusters: VendorClusterSchemaConfig,
6469
6470    /// Concentration limits.
6471    #[serde(default)]
6472    pub dependencies: DependencySchemaConfig,
6473}
6474
6475fn default_vendor_tier_depth() -> u8 {
6476    3
6477}
6478
6479impl Default for VendorNetworkSchemaConfig {
6480    fn default() -> Self {
6481        Self {
6482            enabled: false,
6483            depth: 3,
6484            tier1: TierCountSchemaConfig { min: 50, max: 100 },
6485            tier2_per_parent: TierCountSchemaConfig { min: 4, max: 10 },
6486            tier3_per_parent: TierCountSchemaConfig { min: 2, max: 5 },
6487            clusters: VendorClusterSchemaConfig::default(),
6488            dependencies: DependencySchemaConfig::default(),
6489        }
6490    }
6491}
6492
6493/// Tier count configuration.
6494#[derive(Debug, Clone, Serialize, Deserialize)]
6495pub struct TierCountSchemaConfig {
6496    /// Minimum count.
6497    #[serde(default = "default_tier_min")]
6498    pub min: usize,
6499
6500    /// Maximum count.
6501    #[serde(default = "default_tier_max")]
6502    pub max: usize,
6503}
6504
6505fn default_tier_min() -> usize {
6506    5
6507}
6508
6509fn default_tier_max() -> usize {
6510    20
6511}
6512
6513impl Default for TierCountSchemaConfig {
6514    fn default() -> Self {
6515        Self {
6516            min: default_tier_min(),
6517            max: default_tier_max(),
6518        }
6519    }
6520}
6521
6522/// Vendor cluster distribution configuration.
6523#[derive(Debug, Clone, Serialize, Deserialize)]
6524pub struct VendorClusterSchemaConfig {
6525    /// Reliable strategic vendors percentage (default: 0.20).
6526    #[serde(default = "default_reliable_strategic")]
6527    pub reliable_strategic: f64,
6528
6529    /// Standard operational vendors percentage (default: 0.50).
6530    #[serde(default = "default_standard_operational")]
6531    pub standard_operational: f64,
6532
6533    /// Transactional vendors percentage (default: 0.25).
6534    #[serde(default = "default_transactional")]
6535    pub transactional: f64,
6536
6537    /// Problematic vendors percentage (default: 0.05).
6538    #[serde(default = "default_problematic")]
6539    pub problematic: f64,
6540}
6541
6542fn default_reliable_strategic() -> f64 {
6543    0.20
6544}
6545
6546fn default_standard_operational() -> f64 {
6547    0.50
6548}
6549
6550fn default_transactional() -> f64 {
6551    0.25
6552}
6553
6554fn default_problematic() -> f64 {
6555    0.05
6556}
6557
6558impl Default for VendorClusterSchemaConfig {
6559    fn default() -> Self {
6560        Self {
6561            reliable_strategic: 0.20,
6562            standard_operational: 0.50,
6563            transactional: 0.25,
6564            problematic: 0.05,
6565        }
6566    }
6567}
6568
6569/// Dependency and concentration limits configuration.
6570#[derive(Debug, Clone, Serialize, Deserialize)]
6571pub struct DependencySchemaConfig {
6572    /// Maximum concentration for a single vendor (default: 0.15).
6573    #[serde(default = "default_max_single_vendor")]
6574    pub max_single_vendor_concentration: f64,
6575
6576    /// Maximum concentration for top 5 vendors (default: 0.45).
6577    #[serde(default = "default_max_top5")]
6578    pub top_5_concentration: f64,
6579
6580    /// Percentage of single-source vendors (default: 0.05).
6581    #[serde(default = "default_single_source_percent")]
6582    pub single_source_percent: f64,
6583}
6584
6585fn default_max_single_vendor() -> f64 {
6586    0.15
6587}
6588
6589fn default_max_top5() -> f64 {
6590    0.45
6591}
6592
6593fn default_single_source_percent() -> f64 {
6594    0.05
6595}
6596
6597impl Default for DependencySchemaConfig {
6598    fn default() -> Self {
6599        Self {
6600            max_single_vendor_concentration: 0.15,
6601            top_5_concentration: 0.45,
6602            single_source_percent: 0.05,
6603        }
6604    }
6605}
6606
6607// =============================================================================
6608// Customer Segmentation Configuration
6609// =============================================================================
6610
6611/// Configuration for customer segmentation generation.
6612#[derive(Debug, Clone, Default, Serialize, Deserialize)]
6613pub struct CustomerSegmentationSchemaConfig {
6614    /// Enable customer segmentation generation.
6615    #[serde(default)]
6616    pub enabled: bool,
6617
6618    /// Value segment distribution.
6619    #[serde(default)]
6620    pub value_segments: ValueSegmentsSchemaConfig,
6621
6622    /// Lifecycle stage configuration.
6623    #[serde(default)]
6624    pub lifecycle: LifecycleSchemaConfig,
6625
6626    /// Network (referrals, hierarchies) configuration.
6627    #[serde(default)]
6628    pub networks: CustomerNetworksSchemaConfig,
6629}
6630
6631/// Customer value segments distribution configuration.
6632#[derive(Debug, Clone, Serialize, Deserialize)]
6633pub struct ValueSegmentsSchemaConfig {
6634    /// Enterprise segment configuration.
6635    #[serde(default)]
6636    pub enterprise: SegmentDetailSchemaConfig,
6637
6638    /// Mid-market segment configuration.
6639    #[serde(default)]
6640    pub mid_market: SegmentDetailSchemaConfig,
6641
6642    /// SMB segment configuration.
6643    #[serde(default)]
6644    pub smb: SegmentDetailSchemaConfig,
6645
6646    /// Consumer segment configuration.
6647    #[serde(default)]
6648    pub consumer: SegmentDetailSchemaConfig,
6649}
6650
6651impl Default for ValueSegmentsSchemaConfig {
6652    fn default() -> Self {
6653        Self {
6654            enterprise: SegmentDetailSchemaConfig {
6655                revenue_share: 0.40,
6656                customer_share: 0.05,
6657                avg_order_value_range: "50000+".to_string(),
6658            },
6659            mid_market: SegmentDetailSchemaConfig {
6660                revenue_share: 0.35,
6661                customer_share: 0.20,
6662                avg_order_value_range: "5000-50000".to_string(),
6663            },
6664            smb: SegmentDetailSchemaConfig {
6665                revenue_share: 0.20,
6666                customer_share: 0.50,
6667                avg_order_value_range: "500-5000".to_string(),
6668            },
6669            consumer: SegmentDetailSchemaConfig {
6670                revenue_share: 0.05,
6671                customer_share: 0.25,
6672                avg_order_value_range: "50-500".to_string(),
6673            },
6674        }
6675    }
6676}
6677
6678/// Individual segment detail configuration.
6679#[derive(Debug, Clone, Serialize, Deserialize)]
6680pub struct SegmentDetailSchemaConfig {
6681    /// Revenue share for this segment.
6682    #[serde(default)]
6683    pub revenue_share: f64,
6684
6685    /// Customer share for this segment.
6686    #[serde(default)]
6687    pub customer_share: f64,
6688
6689    /// Average order value range (e.g., "5000-50000" or "50000+").
6690    #[serde(default)]
6691    pub avg_order_value_range: String,
6692}
6693
6694impl Default for SegmentDetailSchemaConfig {
6695    fn default() -> Self {
6696        Self {
6697            revenue_share: 0.25,
6698            customer_share: 0.25,
6699            avg_order_value_range: "1000-10000".to_string(),
6700        }
6701    }
6702}
6703
6704/// Customer lifecycle stage configuration.
6705#[derive(Debug, Clone, Serialize, Deserialize)]
6706pub struct LifecycleSchemaConfig {
6707    /// Prospect stage rate.
6708    #[serde(default)]
6709    pub prospect_rate: f64,
6710
6711    /// New customer stage rate.
6712    #[serde(default = "default_new_rate")]
6713    pub new_rate: f64,
6714
6715    /// Growth stage rate.
6716    #[serde(default = "default_growth_rate")]
6717    pub growth_rate: f64,
6718
6719    /// Mature stage rate.
6720    #[serde(default = "default_mature_rate")]
6721    pub mature_rate: f64,
6722
6723    /// At-risk stage rate.
6724    #[serde(default = "default_at_risk_rate")]
6725    pub at_risk_rate: f64,
6726
6727    /// Churned stage rate.
6728    #[serde(default = "default_churned_rate")]
6729    pub churned_rate: f64,
6730}
6731
6732fn default_new_rate() -> f64 {
6733    0.10
6734}
6735
6736fn default_growth_rate() -> f64 {
6737    0.15
6738}
6739
6740fn default_mature_rate() -> f64 {
6741    0.60
6742}
6743
6744fn default_at_risk_rate() -> f64 {
6745    0.10
6746}
6747
6748fn default_churned_rate() -> f64 {
6749    0.05
6750}
6751
6752impl Default for LifecycleSchemaConfig {
6753    fn default() -> Self {
6754        Self {
6755            prospect_rate: 0.0,
6756            new_rate: 0.10,
6757            growth_rate: 0.15,
6758            mature_rate: 0.60,
6759            at_risk_rate: 0.10,
6760            churned_rate: 0.05,
6761        }
6762    }
6763}
6764
6765/// Customer networks configuration (referrals, hierarchies).
6766#[derive(Debug, Clone, Default, Serialize, Deserialize)]
6767pub struct CustomerNetworksSchemaConfig {
6768    /// Referral network configuration.
6769    #[serde(default)]
6770    pub referrals: ReferralSchemaConfig,
6771
6772    /// Corporate hierarchy configuration.
6773    #[serde(default)]
6774    pub corporate_hierarchies: HierarchySchemaConfig,
6775}
6776
6777/// Referral network configuration.
6778#[derive(Debug, Clone, Serialize, Deserialize)]
6779pub struct ReferralSchemaConfig {
6780    /// Enable referral generation.
6781    #[serde(default = "default_true")]
6782    pub enabled: bool,
6783
6784    /// Rate of customers acquired via referral.
6785    #[serde(default = "default_referral_rate")]
6786    pub referral_rate: f64,
6787}
6788
6789fn default_referral_rate() -> f64 {
6790    0.15
6791}
6792
6793impl Default for ReferralSchemaConfig {
6794    fn default() -> Self {
6795        Self {
6796            enabled: true,
6797            referral_rate: 0.15,
6798        }
6799    }
6800}
6801
6802/// Corporate hierarchy configuration.
6803#[derive(Debug, Clone, Serialize, Deserialize)]
6804pub struct HierarchySchemaConfig {
6805    /// Enable corporate hierarchy generation.
6806    #[serde(default = "default_true")]
6807    pub enabled: bool,
6808
6809    /// Rate of customers in hierarchies.
6810    #[serde(default = "default_hierarchy_rate")]
6811    pub probability: f64,
6812}
6813
6814fn default_hierarchy_rate() -> f64 {
6815    0.30
6816}
6817
6818impl Default for HierarchySchemaConfig {
6819    fn default() -> Self {
6820        Self {
6821            enabled: true,
6822            probability: 0.30,
6823        }
6824    }
6825}
6826
6827// =============================================================================
6828// Relationship Strength Configuration
6829// =============================================================================
6830
6831/// Configuration for relationship strength calculation.
6832#[derive(Debug, Clone, Default, Serialize, Deserialize)]
6833pub struct RelationshipStrengthSchemaConfig {
6834    /// Enable relationship strength calculation.
6835    #[serde(default)]
6836    pub enabled: bool,
6837
6838    /// Calculation weights.
6839    #[serde(default)]
6840    pub calculation: StrengthCalculationSchemaConfig,
6841
6842    /// Strength thresholds for classification.
6843    #[serde(default)]
6844    pub thresholds: StrengthThresholdsSchemaConfig,
6845}
6846
6847/// Strength calculation weights configuration.
6848#[derive(Debug, Clone, Serialize, Deserialize)]
6849pub struct StrengthCalculationSchemaConfig {
6850    /// Weight for transaction volume (default: 0.30).
6851    #[serde(default = "default_volume_weight")]
6852    pub transaction_volume_weight: f64,
6853
6854    /// Weight for transaction count (default: 0.25).
6855    #[serde(default = "default_count_weight")]
6856    pub transaction_count_weight: f64,
6857
6858    /// Weight for relationship duration (default: 0.20).
6859    #[serde(default = "default_duration_weight")]
6860    pub relationship_duration_weight: f64,
6861
6862    /// Weight for recency (default: 0.15).
6863    #[serde(default = "default_recency_weight")]
6864    pub recency_weight: f64,
6865
6866    /// Weight for mutual connections (default: 0.10).
6867    #[serde(default = "default_mutual_weight")]
6868    pub mutual_connections_weight: f64,
6869
6870    /// Recency half-life in days (default: 90).
6871    #[serde(default = "default_recency_half_life")]
6872    pub recency_half_life_days: u32,
6873}
6874
6875fn default_volume_weight() -> f64 {
6876    0.30
6877}
6878
6879fn default_count_weight() -> f64 {
6880    0.25
6881}
6882
6883fn default_duration_weight() -> f64 {
6884    0.20
6885}
6886
6887fn default_recency_weight() -> f64 {
6888    0.15
6889}
6890
6891fn default_mutual_weight() -> f64 {
6892    0.10
6893}
6894
6895fn default_recency_half_life() -> u32 {
6896    90
6897}
6898
6899impl Default for StrengthCalculationSchemaConfig {
6900    fn default() -> Self {
6901        Self {
6902            transaction_volume_weight: 0.30,
6903            transaction_count_weight: 0.25,
6904            relationship_duration_weight: 0.20,
6905            recency_weight: 0.15,
6906            mutual_connections_weight: 0.10,
6907            recency_half_life_days: 90,
6908        }
6909    }
6910}
6911
6912/// Strength thresholds for relationship classification.
6913#[derive(Debug, Clone, Serialize, Deserialize)]
6914pub struct StrengthThresholdsSchemaConfig {
6915    /// Threshold for strong relationships (default: 0.7).
6916    #[serde(default = "default_strong_threshold")]
6917    pub strong: f64,
6918
6919    /// Threshold for moderate relationships (default: 0.4).
6920    #[serde(default = "default_moderate_threshold")]
6921    pub moderate: f64,
6922
6923    /// Threshold for weak relationships (default: 0.1).
6924    #[serde(default = "default_weak_threshold")]
6925    pub weak: f64,
6926}
6927
6928fn default_strong_threshold() -> f64 {
6929    0.7
6930}
6931
6932fn default_moderate_threshold() -> f64 {
6933    0.4
6934}
6935
6936fn default_weak_threshold() -> f64 {
6937    0.1
6938}
6939
6940impl Default for StrengthThresholdsSchemaConfig {
6941    fn default() -> Self {
6942        Self {
6943            strong: 0.7,
6944            moderate: 0.4,
6945            weak: 0.1,
6946        }
6947    }
6948}
6949
6950// =============================================================================
6951// Cross-Process Links Configuration
6952// =============================================================================
6953
6954/// Configuration for cross-process linkages.
6955#[derive(Debug, Clone, Serialize, Deserialize)]
6956pub struct CrossProcessLinksSchemaConfig {
6957    /// Enable cross-process link generation.
6958    #[serde(default)]
6959    pub enabled: bool,
6960
6961    /// Enable inventory links between P2P and O2C.
6962    #[serde(default = "default_true")]
6963    pub inventory_p2p_o2c: bool,
6964
6965    /// Enable payment to bank reconciliation links.
6966    #[serde(default = "default_true")]
6967    pub payment_bank_reconciliation: bool,
6968
6969    /// Enable intercompany bilateral matching.
6970    #[serde(default = "default_true")]
6971    pub intercompany_bilateral: bool,
6972
6973    /// Percentage of GR/Deliveries to link via inventory (0.0 - 1.0).
6974    #[serde(default = "default_inventory_link_rate")]
6975    pub inventory_link_rate: f64,
6976}
6977
6978fn default_inventory_link_rate() -> f64 {
6979    0.30
6980}
6981
6982impl Default for CrossProcessLinksSchemaConfig {
6983    fn default() -> Self {
6984        Self {
6985            enabled: false,
6986            inventory_p2p_o2c: true,
6987            payment_bank_reconciliation: true,
6988            intercompany_bilateral: true,
6989            inventory_link_rate: 0.30,
6990        }
6991    }
6992}
6993
6994// =============================================================================
6995// Organizational Events Configuration
6996// =============================================================================
6997
6998/// Configuration for organizational events (acquisitions, divestitures, etc.).
6999#[derive(Debug, Clone, Serialize, Deserialize, Default)]
7000pub struct OrganizationalEventsSchemaConfig {
7001    /// Enable organizational events.
7002    #[serde(default)]
7003    pub enabled: bool,
7004
7005    /// Effect blending mode (multiplicative, additive, maximum, minimum).
7006    #[serde(default)]
7007    pub effect_blending: EffectBlendingModeConfig,
7008
7009    /// Organizational events (acquisitions, divestitures, reorganizations, etc.).
7010    #[serde(default)]
7011    pub events: Vec<OrganizationalEventSchemaConfig>,
7012
7013    /// Process evolution events.
7014    #[serde(default)]
7015    pub process_evolution: Vec<ProcessEvolutionSchemaConfig>,
7016
7017    /// Technology transition events.
7018    #[serde(default)]
7019    pub technology_transitions: Vec<TechnologyTransitionSchemaConfig>,
7020}
7021
7022/// Effect blending mode for combining multiple event effects.
7023#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
7024#[serde(rename_all = "snake_case")]
7025pub enum EffectBlendingModeConfig {
7026    /// Multiply effects together.
7027    #[default]
7028    Multiplicative,
7029    /// Add effects together.
7030    Additive,
7031    /// Take the maximum effect.
7032    Maximum,
7033    /// Take the minimum effect.
7034    Minimum,
7035}
7036
7037/// Configuration for a single organizational event.
7038#[derive(Debug, Clone, Serialize, Deserialize)]
7039pub struct OrganizationalEventSchemaConfig {
7040    /// Event ID.
7041    pub id: String,
7042
7043    /// Event type and configuration.
7044    pub event_type: OrganizationalEventTypeSchemaConfig,
7045
7046    /// Effective date.
7047    pub effective_date: String,
7048
7049    /// Transition duration in months.
7050    #[serde(default = "default_org_transition_months")]
7051    pub transition_months: u32,
7052
7053    /// Description.
7054    #[serde(default)]
7055    pub description: Option<String>,
7056}
7057
7058fn default_org_transition_months() -> u32 {
7059    6
7060}
7061
7062/// Organizational event type configuration.
7063#[derive(Debug, Clone, Serialize, Deserialize)]
7064#[serde(tag = "type", rename_all = "snake_case")]
7065pub enum OrganizationalEventTypeSchemaConfig {
7066    /// Acquisition event.
7067    Acquisition {
7068        /// Acquired entity code.
7069        acquired_entity: String,
7070        /// Volume increase multiplier.
7071        #[serde(default = "default_acquisition_volume")]
7072        volume_increase: f64,
7073        /// Integration error rate.
7074        #[serde(default = "default_acquisition_error")]
7075        integration_error_rate: f64,
7076        /// Parallel posting days.
7077        #[serde(default = "default_parallel_days")]
7078        parallel_posting_days: u32,
7079    },
7080    /// Divestiture event.
7081    Divestiture {
7082        /// Divested entity code.
7083        divested_entity: String,
7084        /// Volume reduction factor.
7085        #[serde(default = "default_divestiture_volume")]
7086        volume_reduction: f64,
7087        /// Remove entity from generation.
7088        #[serde(default = "default_true_val")]
7089        remove_entity: bool,
7090    },
7091    /// Reorganization event.
7092    Reorganization {
7093        /// Cost center remapping.
7094        #[serde(default)]
7095        cost_center_remapping: std::collections::HashMap<String, String>,
7096        /// Transition error rate.
7097        #[serde(default = "default_reorg_error")]
7098        transition_error_rate: f64,
7099    },
7100    /// Leadership change event.
7101    LeadershipChange {
7102        /// Role that changed.
7103        role: String,
7104        /// Policy changes.
7105        #[serde(default)]
7106        policy_changes: Vec<String>,
7107    },
7108    /// Workforce reduction event.
7109    WorkforceReduction {
7110        /// Reduction percentage.
7111        #[serde(default = "default_workforce_reduction")]
7112        reduction_percent: f64,
7113        /// Error rate increase.
7114        #[serde(default = "default_workforce_error")]
7115        error_rate_increase: f64,
7116    },
7117    /// Merger event.
7118    Merger {
7119        /// Merged entity code.
7120        merged_entity: String,
7121        /// Volume increase multiplier.
7122        #[serde(default = "default_merger_volume")]
7123        volume_increase: f64,
7124    },
7125}
7126
7127fn default_acquisition_volume() -> f64 {
7128    1.35
7129}
7130
7131fn default_acquisition_error() -> f64 {
7132    0.05
7133}
7134
7135fn default_parallel_days() -> u32 {
7136    30
7137}
7138
7139fn default_divestiture_volume() -> f64 {
7140    0.70
7141}
7142
7143fn default_true_val() -> bool {
7144    true
7145}
7146
7147fn default_reorg_error() -> f64 {
7148    0.04
7149}
7150
7151fn default_workforce_reduction() -> f64 {
7152    0.10
7153}
7154
7155fn default_workforce_error() -> f64 {
7156    0.05
7157}
7158
7159fn default_merger_volume() -> f64 {
7160    1.80
7161}
7162
7163/// Configuration for a process evolution event.
7164#[derive(Debug, Clone, Serialize, Deserialize)]
7165pub struct ProcessEvolutionSchemaConfig {
7166    /// Event ID.
7167    pub id: String,
7168
7169    /// Event type.
7170    pub event_type: ProcessEvolutionTypeSchemaConfig,
7171
7172    /// Effective date.
7173    pub effective_date: String,
7174
7175    /// Description.
7176    #[serde(default)]
7177    pub description: Option<String>,
7178}
7179
7180/// Process evolution type configuration.
7181#[derive(Debug, Clone, Serialize, Deserialize)]
7182#[serde(tag = "type", rename_all = "snake_case")]
7183pub enum ProcessEvolutionTypeSchemaConfig {
7184    /// Process automation.
7185    ProcessAutomation {
7186        /// Process name.
7187        process_name: String,
7188        /// Manual rate before.
7189        #[serde(default = "default_manual_before")]
7190        manual_rate_before: f64,
7191        /// Manual rate after.
7192        #[serde(default = "default_manual_after")]
7193        manual_rate_after: f64,
7194    },
7195    /// Approval workflow change.
7196    ApprovalWorkflowChange {
7197        /// Description.
7198        description: String,
7199    },
7200    /// Control enhancement.
7201    ControlEnhancement {
7202        /// Control ID.
7203        control_id: String,
7204        /// Error reduction.
7205        #[serde(default = "default_error_reduction")]
7206        error_reduction: f64,
7207    },
7208}
7209
7210fn default_manual_before() -> f64 {
7211    0.80
7212}
7213
7214fn default_manual_after() -> f64 {
7215    0.15
7216}
7217
7218fn default_error_reduction() -> f64 {
7219    0.02
7220}
7221
7222/// Configuration for a technology transition event.
7223#[derive(Debug, Clone, Serialize, Deserialize)]
7224pub struct TechnologyTransitionSchemaConfig {
7225    /// Event ID.
7226    pub id: String,
7227
7228    /// Event type.
7229    pub event_type: TechnologyTransitionTypeSchemaConfig,
7230
7231    /// Description.
7232    #[serde(default)]
7233    pub description: Option<String>,
7234}
7235
7236/// Technology transition type configuration.
7237#[derive(Debug, Clone, Serialize, Deserialize)]
7238#[serde(tag = "type", rename_all = "snake_case")]
7239pub enum TechnologyTransitionTypeSchemaConfig {
7240    /// ERP migration.
7241    ErpMigration {
7242        /// Source system.
7243        source_system: String,
7244        /// Target system.
7245        target_system: String,
7246        /// Cutover date.
7247        cutover_date: String,
7248        /// Stabilization end date.
7249        stabilization_end: String,
7250        /// Duplicate rate during migration.
7251        #[serde(default = "default_erp_duplicate_rate")]
7252        duplicate_rate: f64,
7253        /// Format mismatch rate.
7254        #[serde(default = "default_format_mismatch")]
7255        format_mismatch_rate: f64,
7256    },
7257    /// Module implementation.
7258    ModuleImplementation {
7259        /// Module name.
7260        module_name: String,
7261        /// Go-live date.
7262        go_live_date: String,
7263    },
7264}
7265
7266fn default_erp_duplicate_rate() -> f64 {
7267    0.02
7268}
7269
7270fn default_format_mismatch() -> f64 {
7271    0.03
7272}
7273
7274// =============================================================================
7275// Behavioral Drift Configuration
7276// =============================================================================
7277
7278/// Configuration for behavioral drift (vendor, customer, employee behavior).
7279#[derive(Debug, Clone, Serialize, Deserialize, Default)]
7280pub struct BehavioralDriftSchemaConfig {
7281    /// Enable behavioral drift.
7282    #[serde(default)]
7283    pub enabled: bool,
7284
7285    /// Vendor behavior drift.
7286    #[serde(default)]
7287    pub vendor_behavior: VendorBehaviorSchemaConfig,
7288
7289    /// Customer behavior drift.
7290    #[serde(default)]
7291    pub customer_behavior: CustomerBehaviorSchemaConfig,
7292
7293    /// Employee behavior drift.
7294    #[serde(default)]
7295    pub employee_behavior: EmployeeBehaviorSchemaConfig,
7296
7297    /// Collective behavior drift.
7298    #[serde(default)]
7299    pub collective: CollectiveBehaviorSchemaConfig,
7300}
7301
7302/// Vendor behavior drift configuration.
7303#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7304pub struct VendorBehaviorSchemaConfig {
7305    /// Payment terms drift.
7306    #[serde(default)]
7307    pub payment_terms_drift: PaymentTermsDriftSchemaConfig,
7308
7309    /// Quality drift.
7310    #[serde(default)]
7311    pub quality_drift: QualityDriftSchemaConfig,
7312}
7313
7314/// Payment terms drift configuration.
7315#[derive(Debug, Clone, Serialize, Deserialize)]
7316pub struct PaymentTermsDriftSchemaConfig {
7317    /// Extension rate per year (days).
7318    #[serde(default = "default_extension_rate")]
7319    pub extension_rate_per_year: f64,
7320
7321    /// Economic sensitivity.
7322    #[serde(default = "default_economic_sensitivity")]
7323    pub economic_sensitivity: f64,
7324}
7325
7326fn default_extension_rate() -> f64 {
7327    2.5
7328}
7329
7330fn default_economic_sensitivity() -> f64 {
7331    1.0
7332}
7333
7334impl Default for PaymentTermsDriftSchemaConfig {
7335    fn default() -> Self {
7336        Self {
7337            extension_rate_per_year: 2.5,
7338            economic_sensitivity: 1.0,
7339        }
7340    }
7341}
7342
7343/// Quality drift configuration.
7344#[derive(Debug, Clone, Serialize, Deserialize)]
7345pub struct QualityDriftSchemaConfig {
7346    /// New vendor improvement rate (per year).
7347    #[serde(default = "default_improvement_rate")]
7348    pub new_vendor_improvement_rate: f64,
7349
7350    /// Complacency decline rate (per year after first year).
7351    #[serde(default = "default_decline_rate")]
7352    pub complacency_decline_rate: f64,
7353}
7354
7355fn default_improvement_rate() -> f64 {
7356    0.02
7357}
7358
7359fn default_decline_rate() -> f64 {
7360    0.01
7361}
7362
7363impl Default for QualityDriftSchemaConfig {
7364    fn default() -> Self {
7365        Self {
7366            new_vendor_improvement_rate: 0.02,
7367            complacency_decline_rate: 0.01,
7368        }
7369    }
7370}
7371
7372/// Customer behavior drift configuration.
7373#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7374pub struct CustomerBehaviorSchemaConfig {
7375    /// Payment drift.
7376    #[serde(default)]
7377    pub payment_drift: CustomerPaymentDriftSchemaConfig,
7378
7379    /// Order drift.
7380    #[serde(default)]
7381    pub order_drift: OrderDriftSchemaConfig,
7382}
7383
7384/// Customer payment drift configuration.
7385#[derive(Debug, Clone, Serialize, Deserialize)]
7386pub struct CustomerPaymentDriftSchemaConfig {
7387    /// Days extension during downturn (min, max).
7388    #[serde(default = "default_downturn_extension")]
7389    pub downturn_days_extension: (u32, u32),
7390
7391    /// Bad debt increase during downturn.
7392    #[serde(default = "default_bad_debt_increase")]
7393    pub downturn_bad_debt_increase: f64,
7394}
7395
7396fn default_downturn_extension() -> (u32, u32) {
7397    (5, 15)
7398}
7399
7400fn default_bad_debt_increase() -> f64 {
7401    0.02
7402}
7403
7404impl Default for CustomerPaymentDriftSchemaConfig {
7405    fn default() -> Self {
7406        Self {
7407            downturn_days_extension: (5, 15),
7408            downturn_bad_debt_increase: 0.02,
7409        }
7410    }
7411}
7412
7413/// Order drift configuration.
7414#[derive(Debug, Clone, Serialize, Deserialize)]
7415pub struct OrderDriftSchemaConfig {
7416    /// Digital shift rate (per year).
7417    #[serde(default = "default_digital_shift")]
7418    pub digital_shift_rate: f64,
7419}
7420
7421fn default_digital_shift() -> f64 {
7422    0.05
7423}
7424
7425impl Default for OrderDriftSchemaConfig {
7426    fn default() -> Self {
7427        Self {
7428            digital_shift_rate: 0.05,
7429        }
7430    }
7431}
7432
7433/// Employee behavior drift configuration.
7434#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7435pub struct EmployeeBehaviorSchemaConfig {
7436    /// Approval drift.
7437    #[serde(default)]
7438    pub approval_drift: ApprovalDriftSchemaConfig,
7439
7440    /// Error drift.
7441    #[serde(default)]
7442    pub error_drift: ErrorDriftSchemaConfig,
7443}
7444
7445/// Approval drift configuration.
7446#[derive(Debug, Clone, Serialize, Deserialize)]
7447pub struct ApprovalDriftSchemaConfig {
7448    /// EOM intensity increase per year.
7449    #[serde(default = "default_eom_intensity")]
7450    pub eom_intensity_increase_per_year: f64,
7451
7452    /// Rubber stamp volume threshold.
7453    #[serde(default = "default_rubber_stamp")]
7454    pub rubber_stamp_volume_threshold: u32,
7455}
7456
7457fn default_eom_intensity() -> f64 {
7458    0.05
7459}
7460
7461fn default_rubber_stamp() -> u32 {
7462    50
7463}
7464
7465impl Default for ApprovalDriftSchemaConfig {
7466    fn default() -> Self {
7467        Self {
7468            eom_intensity_increase_per_year: 0.05,
7469            rubber_stamp_volume_threshold: 50,
7470        }
7471    }
7472}
7473
7474/// Error drift configuration.
7475#[derive(Debug, Clone, Serialize, Deserialize)]
7476pub struct ErrorDriftSchemaConfig {
7477    /// New employee error rate.
7478    #[serde(default = "default_new_error")]
7479    pub new_employee_error_rate: f64,
7480
7481    /// Learning curve months.
7482    #[serde(default = "default_learning_months")]
7483    pub learning_curve_months: u32,
7484}
7485
7486fn default_new_error() -> f64 {
7487    0.08
7488}
7489
7490fn default_learning_months() -> u32 {
7491    6
7492}
7493
7494impl Default for ErrorDriftSchemaConfig {
7495    fn default() -> Self {
7496        Self {
7497            new_employee_error_rate: 0.08,
7498            learning_curve_months: 6,
7499        }
7500    }
7501}
7502
7503/// Collective behavior drift configuration.
7504#[derive(Debug, Clone, Serialize, Deserialize, Default)]
7505pub struct CollectiveBehaviorSchemaConfig {
7506    /// Automation adoption configuration.
7507    #[serde(default)]
7508    pub automation_adoption: AutomationAdoptionSchemaConfig,
7509}
7510
7511/// Automation adoption configuration.
7512#[derive(Debug, Clone, Serialize, Deserialize)]
7513pub struct AutomationAdoptionSchemaConfig {
7514    /// Enable S-curve adoption model.
7515    #[serde(default)]
7516    pub s_curve_enabled: bool,
7517
7518    /// Adoption midpoint in months.
7519    #[serde(default = "default_midpoint")]
7520    pub adoption_midpoint_months: u32,
7521
7522    /// Steepness of adoption curve.
7523    #[serde(default = "default_steepness")]
7524    pub steepness: f64,
7525}
7526
7527fn default_midpoint() -> u32 {
7528    24
7529}
7530
7531fn default_steepness() -> f64 {
7532    0.15
7533}
7534
7535impl Default for AutomationAdoptionSchemaConfig {
7536    fn default() -> Self {
7537        Self {
7538            s_curve_enabled: false,
7539            adoption_midpoint_months: 24,
7540            steepness: 0.15,
7541        }
7542    }
7543}
7544
7545// =============================================================================
7546// Market Drift Configuration
7547// =============================================================================
7548
7549/// Configuration for market drift (economic cycles, commodities, price shocks).
7550#[derive(Debug, Clone, Serialize, Deserialize, Default)]
7551pub struct MarketDriftSchemaConfig {
7552    /// Enable market drift.
7553    #[serde(default)]
7554    pub enabled: bool,
7555
7556    /// Economic cycle configuration.
7557    #[serde(default)]
7558    pub economic_cycle: MarketEconomicCycleSchemaConfig,
7559
7560    /// Industry-specific cycles.
7561    #[serde(default)]
7562    pub industry_cycles: std::collections::HashMap<String, IndustryCycleSchemaConfig>,
7563
7564    /// Commodity drift configuration.
7565    #[serde(default)]
7566    pub commodities: CommoditiesSchemaConfig,
7567}
7568
7569/// Market economic cycle configuration.
7570#[derive(Debug, Clone, Serialize, Deserialize)]
7571pub struct MarketEconomicCycleSchemaConfig {
7572    /// Enable economic cycle.
7573    #[serde(default)]
7574    pub enabled: bool,
7575
7576    /// Cycle type.
7577    #[serde(default)]
7578    pub cycle_type: CycleTypeSchemaConfig,
7579
7580    /// Cycle period in months.
7581    #[serde(default = "default_market_cycle_period")]
7582    pub period_months: u32,
7583
7584    /// Amplitude.
7585    #[serde(default = "default_market_amplitude")]
7586    pub amplitude: f64,
7587
7588    /// Recession configuration.
7589    #[serde(default)]
7590    pub recession: RecessionSchemaConfig,
7591}
7592
7593fn default_market_cycle_period() -> u32 {
7594    48
7595}
7596
7597fn default_market_amplitude() -> f64 {
7598    0.15
7599}
7600
7601impl Default for MarketEconomicCycleSchemaConfig {
7602    fn default() -> Self {
7603        Self {
7604            enabled: false,
7605            cycle_type: CycleTypeSchemaConfig::Sinusoidal,
7606            period_months: 48,
7607            amplitude: 0.15,
7608            recession: RecessionSchemaConfig::default(),
7609        }
7610    }
7611}
7612
7613/// Cycle type configuration.
7614#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
7615#[serde(rename_all = "snake_case")]
7616pub enum CycleTypeSchemaConfig {
7617    /// Sinusoidal cycle.
7618    #[default]
7619    Sinusoidal,
7620    /// Asymmetric cycle.
7621    Asymmetric,
7622    /// Mean-reverting cycle.
7623    MeanReverting,
7624}
7625
7626/// Recession configuration.
7627#[derive(Debug, Clone, Serialize, Deserialize)]
7628pub struct RecessionSchemaConfig {
7629    /// Enable recession simulation.
7630    #[serde(default)]
7631    pub enabled: bool,
7632
7633    /// Probability per year.
7634    #[serde(default = "default_recession_prob")]
7635    pub probability_per_year: f64,
7636
7637    /// Severity.
7638    #[serde(default)]
7639    pub severity: RecessionSeveritySchemaConfig,
7640
7641    /// Specific recession periods.
7642    #[serde(default)]
7643    pub recession_periods: Vec<RecessionPeriodSchemaConfig>,
7644}
7645
7646fn default_recession_prob() -> f64 {
7647    0.10
7648}
7649
7650impl Default for RecessionSchemaConfig {
7651    fn default() -> Self {
7652        Self {
7653            enabled: false,
7654            probability_per_year: 0.10,
7655            severity: RecessionSeveritySchemaConfig::Moderate,
7656            recession_periods: Vec::new(),
7657        }
7658    }
7659}
7660
7661/// Recession severity configuration.
7662#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
7663#[serde(rename_all = "snake_case")]
7664pub enum RecessionSeveritySchemaConfig {
7665    /// Mild recession.
7666    Mild,
7667    /// Moderate recession.
7668    #[default]
7669    Moderate,
7670    /// Severe recession.
7671    Severe,
7672}
7673
7674/// Recession period configuration.
7675#[derive(Debug, Clone, Serialize, Deserialize)]
7676pub struct RecessionPeriodSchemaConfig {
7677    /// Start month.
7678    pub start_month: u32,
7679    /// Duration in months.
7680    pub duration_months: u32,
7681}
7682
7683/// Industry cycle configuration.
7684#[derive(Debug, Clone, Serialize, Deserialize)]
7685pub struct IndustryCycleSchemaConfig {
7686    /// Period in months.
7687    #[serde(default = "default_industry_period")]
7688    pub period_months: u32,
7689
7690    /// Amplitude.
7691    #[serde(default = "default_industry_amp")]
7692    pub amplitude: f64,
7693}
7694
7695fn default_industry_period() -> u32 {
7696    36
7697}
7698
7699fn default_industry_amp() -> f64 {
7700    0.20
7701}
7702
7703/// Commodities drift configuration.
7704#[derive(Debug, Clone, Serialize, Deserialize, Default)]
7705pub struct CommoditiesSchemaConfig {
7706    /// Enable commodity drift.
7707    #[serde(default)]
7708    pub enabled: bool,
7709
7710    /// Commodity items.
7711    #[serde(default)]
7712    pub items: Vec<CommodityItemSchemaConfig>,
7713}
7714
7715/// Commodity item configuration.
7716#[derive(Debug, Clone, Serialize, Deserialize)]
7717pub struct CommodityItemSchemaConfig {
7718    /// Commodity name.
7719    pub name: String,
7720
7721    /// Volatility.
7722    #[serde(default = "default_volatility")]
7723    pub volatility: f64,
7724
7725    /// COGS pass-through.
7726    #[serde(default)]
7727    pub cogs_pass_through: f64,
7728
7729    /// Overhead pass-through.
7730    #[serde(default)]
7731    pub overhead_pass_through: f64,
7732}
7733
7734fn default_volatility() -> f64 {
7735    0.20
7736}
7737
7738// =============================================================================
7739// Drift Labeling Configuration
7740// =============================================================================
7741
7742/// Configuration for drift ground truth labeling.
7743#[derive(Debug, Clone, Serialize, Deserialize, Default)]
7744pub struct DriftLabelingSchemaConfig {
7745    /// Enable drift labeling.
7746    #[serde(default)]
7747    pub enabled: bool,
7748
7749    /// Statistical drift labeling.
7750    #[serde(default)]
7751    pub statistical: StatisticalDriftLabelingSchemaConfig,
7752
7753    /// Categorical drift labeling.
7754    #[serde(default)]
7755    pub categorical: CategoricalDriftLabelingSchemaConfig,
7756
7757    /// Temporal drift labeling.
7758    #[serde(default)]
7759    pub temporal: TemporalDriftLabelingSchemaConfig,
7760
7761    /// Regulatory calendar preset.
7762    #[serde(default)]
7763    pub regulatory_calendar_preset: Option<String>,
7764}
7765
7766/// Statistical drift labeling configuration.
7767#[derive(Debug, Clone, Serialize, Deserialize)]
7768pub struct StatisticalDriftLabelingSchemaConfig {
7769    /// Enable statistical drift labeling.
7770    #[serde(default = "default_true_val")]
7771    pub enabled: bool,
7772
7773    /// Minimum magnitude threshold.
7774    #[serde(default = "default_min_magnitude")]
7775    pub min_magnitude_threshold: f64,
7776}
7777
7778fn default_min_magnitude() -> f64 {
7779    0.05
7780}
7781
7782impl Default for StatisticalDriftLabelingSchemaConfig {
7783    fn default() -> Self {
7784        Self {
7785            enabled: true,
7786            min_magnitude_threshold: 0.05,
7787        }
7788    }
7789}
7790
7791/// Categorical drift labeling configuration.
7792#[derive(Debug, Clone, Serialize, Deserialize)]
7793pub struct CategoricalDriftLabelingSchemaConfig {
7794    /// Enable categorical drift labeling.
7795    #[serde(default = "default_true_val")]
7796    pub enabled: bool,
7797}
7798
7799impl Default for CategoricalDriftLabelingSchemaConfig {
7800    fn default() -> Self {
7801        Self { enabled: true }
7802    }
7803}
7804
7805/// Temporal drift labeling configuration.
7806#[derive(Debug, Clone, Serialize, Deserialize)]
7807pub struct TemporalDriftLabelingSchemaConfig {
7808    /// Enable temporal drift labeling.
7809    #[serde(default = "default_true_val")]
7810    pub enabled: bool,
7811}
7812
7813impl Default for TemporalDriftLabelingSchemaConfig {
7814    fn default() -> Self {
7815        Self { enabled: true }
7816    }
7817}
7818
7819// =============================================================================
7820// Enhanced Anomaly Injection Configuration
7821// =============================================================================
7822
7823/// Enhanced anomaly injection configuration.
7824///
7825/// Provides comprehensive anomaly injection capabilities including:
7826/// - Multi-stage fraud schemes (embezzlement, revenue manipulation, kickbacks)
7827/// - Correlated anomaly injection (co-occurrence patterns, error cascades)
7828/// - Near-miss generation for false positive reduction
7829/// - Detection difficulty classification
7830/// - Context-aware injection based on entity behavior
7831#[derive(Debug, Clone, Serialize, Deserialize, Default)]
7832pub struct EnhancedAnomalyConfig {
7833    /// Enable enhanced anomaly injection.
7834    #[serde(default)]
7835    pub enabled: bool,
7836
7837    /// Base anomaly rates.
7838    #[serde(default)]
7839    pub rates: AnomalyRateConfig,
7840
7841    /// Multi-stage fraud scheme configuration.
7842    #[serde(default)]
7843    pub multi_stage_schemes: MultiStageSchemeConfig,
7844
7845    /// Correlated anomaly injection configuration.
7846    #[serde(default)]
7847    pub correlated_injection: CorrelatedInjectionConfig,
7848
7849    /// Near-miss generation configuration.
7850    #[serde(default)]
7851    pub near_miss: NearMissConfig,
7852
7853    /// Detection difficulty classification configuration.
7854    #[serde(default)]
7855    pub difficulty_classification: DifficultyClassificationConfig,
7856
7857    /// Context-aware injection configuration.
7858    #[serde(default)]
7859    pub context_aware: ContextAwareConfig,
7860
7861    /// Enhanced labeling configuration.
7862    #[serde(default)]
7863    pub labeling: EnhancedLabelingConfig,
7864}
7865
7866/// Base anomaly rate configuration.
7867#[derive(Debug, Clone, Serialize, Deserialize)]
7868pub struct AnomalyRateConfig {
7869    /// Total anomaly rate (0.0 to 1.0).
7870    #[serde(default = "default_total_anomaly_rate")]
7871    pub total_rate: f64,
7872
7873    /// Fraud anomaly rate.
7874    #[serde(default = "default_fraud_anomaly_rate")]
7875    pub fraud_rate: f64,
7876
7877    /// Error anomaly rate.
7878    #[serde(default = "default_error_anomaly_rate")]
7879    pub error_rate: f64,
7880
7881    /// Process issue rate.
7882    #[serde(default = "default_process_anomaly_rate")]
7883    pub process_rate: f64,
7884}
7885
7886fn default_total_anomaly_rate() -> f64 {
7887    0.03
7888}
7889fn default_fraud_anomaly_rate() -> f64 {
7890    0.01
7891}
7892fn default_error_anomaly_rate() -> f64 {
7893    0.015
7894}
7895fn default_process_anomaly_rate() -> f64 {
7896    0.005
7897}
7898
7899impl Default for AnomalyRateConfig {
7900    fn default() -> Self {
7901        Self {
7902            total_rate: default_total_anomaly_rate(),
7903            fraud_rate: default_fraud_anomaly_rate(),
7904            error_rate: default_error_anomaly_rate(),
7905            process_rate: default_process_anomaly_rate(),
7906        }
7907    }
7908}
7909
7910/// Multi-stage fraud scheme configuration.
7911#[derive(Debug, Clone, Serialize, Deserialize, Default)]
7912pub struct MultiStageSchemeConfig {
7913    /// Enable multi-stage fraud schemes.
7914    #[serde(default)]
7915    pub enabled: bool,
7916
7917    /// Embezzlement scheme configuration.
7918    #[serde(default)]
7919    pub embezzlement: EmbezzlementSchemeConfig,
7920
7921    /// Revenue manipulation scheme configuration.
7922    #[serde(default)]
7923    pub revenue_manipulation: RevenueManipulationSchemeConfig,
7924
7925    /// Vendor kickback scheme configuration.
7926    #[serde(default)]
7927    pub kickback: KickbackSchemeConfig,
7928}
7929
7930/// Embezzlement scheme configuration.
7931#[derive(Debug, Clone, Serialize, Deserialize)]
7932pub struct EmbezzlementSchemeConfig {
7933    /// Probability of starting an embezzlement scheme per perpetrator per year.
7934    #[serde(default = "default_embezzlement_probability")]
7935    pub probability: f64,
7936
7937    /// Testing stage configuration.
7938    #[serde(default)]
7939    pub testing_stage: SchemeStageConfig,
7940
7941    /// Escalation stage configuration.
7942    #[serde(default)]
7943    pub escalation_stage: SchemeStageConfig,
7944
7945    /// Acceleration stage configuration.
7946    #[serde(default)]
7947    pub acceleration_stage: SchemeStageConfig,
7948
7949    /// Desperation stage configuration.
7950    #[serde(default)]
7951    pub desperation_stage: SchemeStageConfig,
7952}
7953
7954fn default_embezzlement_probability() -> f64 {
7955    0.02
7956}
7957
7958impl Default for EmbezzlementSchemeConfig {
7959    fn default() -> Self {
7960        Self {
7961            probability: default_embezzlement_probability(),
7962            testing_stage: SchemeStageConfig {
7963                duration_months: 2,
7964                amount_min: 100.0,
7965                amount_max: 500.0,
7966                transaction_count_min: 2,
7967                transaction_count_max: 5,
7968                difficulty: "hard".to_string(),
7969            },
7970            escalation_stage: SchemeStageConfig {
7971                duration_months: 6,
7972                amount_min: 500.0,
7973                amount_max: 2000.0,
7974                transaction_count_min: 3,
7975                transaction_count_max: 8,
7976                difficulty: "moderate".to_string(),
7977            },
7978            acceleration_stage: SchemeStageConfig {
7979                duration_months: 3,
7980                amount_min: 2000.0,
7981                amount_max: 10000.0,
7982                transaction_count_min: 5,
7983                transaction_count_max: 12,
7984                difficulty: "easy".to_string(),
7985            },
7986            desperation_stage: SchemeStageConfig {
7987                duration_months: 1,
7988                amount_min: 10000.0,
7989                amount_max: 50000.0,
7990                transaction_count_min: 3,
7991                transaction_count_max: 6,
7992                difficulty: "trivial".to_string(),
7993            },
7994        }
7995    }
7996}
7997
7998/// Revenue manipulation scheme configuration.
7999#[derive(Debug, Clone, Serialize, Deserialize)]
8000pub struct RevenueManipulationSchemeConfig {
8001    /// Probability of starting a revenue manipulation scheme per period.
8002    #[serde(default = "default_revenue_manipulation_probability")]
8003    pub probability: f64,
8004
8005    /// Early revenue recognition inflation target (Q4).
8006    #[serde(default = "default_early_recognition_target")]
8007    pub early_recognition_target: f64,
8008
8009    /// Expense deferral inflation target (Q1).
8010    #[serde(default = "default_expense_deferral_target")]
8011    pub expense_deferral_target: f64,
8012
8013    /// Reserve release inflation target (Q2).
8014    #[serde(default = "default_reserve_release_target")]
8015    pub reserve_release_target: f64,
8016
8017    /// Channel stuffing inflation target (Q4).
8018    #[serde(default = "default_channel_stuffing_target")]
8019    pub channel_stuffing_target: f64,
8020}
8021
8022fn default_revenue_manipulation_probability() -> f64 {
8023    0.01
8024}
8025fn default_early_recognition_target() -> f64 {
8026    0.02
8027}
8028fn default_expense_deferral_target() -> f64 {
8029    0.03
8030}
8031fn default_reserve_release_target() -> f64 {
8032    0.02
8033}
8034fn default_channel_stuffing_target() -> f64 {
8035    0.05
8036}
8037
8038impl Default for RevenueManipulationSchemeConfig {
8039    fn default() -> Self {
8040        Self {
8041            probability: default_revenue_manipulation_probability(),
8042            early_recognition_target: default_early_recognition_target(),
8043            expense_deferral_target: default_expense_deferral_target(),
8044            reserve_release_target: default_reserve_release_target(),
8045            channel_stuffing_target: default_channel_stuffing_target(),
8046        }
8047    }
8048}
8049
8050/// Vendor kickback scheme configuration.
8051#[derive(Debug, Clone, Serialize, Deserialize)]
8052pub struct KickbackSchemeConfig {
8053    /// Probability of starting a kickback scheme.
8054    #[serde(default = "default_kickback_probability")]
8055    pub probability: f64,
8056
8057    /// Minimum price inflation percentage.
8058    #[serde(default = "default_kickback_inflation_min")]
8059    pub inflation_min: f64,
8060
8061    /// Maximum price inflation percentage.
8062    #[serde(default = "default_kickback_inflation_max")]
8063    pub inflation_max: f64,
8064
8065    /// Kickback percentage (of inflation).
8066    #[serde(default = "default_kickback_percent")]
8067    pub kickback_percent: f64,
8068
8069    /// Setup duration in months.
8070    #[serde(default = "default_kickback_setup_months")]
8071    pub setup_months: u32,
8072
8073    /// Main operation duration in months.
8074    #[serde(default = "default_kickback_operation_months")]
8075    pub operation_months: u32,
8076}
8077
8078fn default_kickback_probability() -> f64 {
8079    0.01
8080}
8081fn default_kickback_inflation_min() -> f64 {
8082    0.10
8083}
8084fn default_kickback_inflation_max() -> f64 {
8085    0.25
8086}
8087fn default_kickback_percent() -> f64 {
8088    0.50
8089}
8090fn default_kickback_setup_months() -> u32 {
8091    3
8092}
8093fn default_kickback_operation_months() -> u32 {
8094    12
8095}
8096
8097impl Default for KickbackSchemeConfig {
8098    fn default() -> Self {
8099        Self {
8100            probability: default_kickback_probability(),
8101            inflation_min: default_kickback_inflation_min(),
8102            inflation_max: default_kickback_inflation_max(),
8103            kickback_percent: default_kickback_percent(),
8104            setup_months: default_kickback_setup_months(),
8105            operation_months: default_kickback_operation_months(),
8106        }
8107    }
8108}
8109
8110/// Individual scheme stage configuration.
8111#[derive(Debug, Clone, Serialize, Deserialize)]
8112pub struct SchemeStageConfig {
8113    /// Duration in months.
8114    pub duration_months: u32,
8115
8116    /// Minimum transaction amount.
8117    pub amount_min: f64,
8118
8119    /// Maximum transaction amount.
8120    pub amount_max: f64,
8121
8122    /// Minimum number of transactions.
8123    pub transaction_count_min: u32,
8124
8125    /// Maximum number of transactions.
8126    pub transaction_count_max: u32,
8127
8128    /// Detection difficulty level (trivial, easy, moderate, hard, expert).
8129    pub difficulty: String,
8130}
8131
8132impl Default for SchemeStageConfig {
8133    fn default() -> Self {
8134        Self {
8135            duration_months: 3,
8136            amount_min: 100.0,
8137            amount_max: 1000.0,
8138            transaction_count_min: 2,
8139            transaction_count_max: 10,
8140            difficulty: "moderate".to_string(),
8141        }
8142    }
8143}
8144
8145/// Correlated anomaly injection configuration.
8146#[derive(Debug, Clone, Serialize, Deserialize)]
8147pub struct CorrelatedInjectionConfig {
8148    /// Enable correlated anomaly injection.
8149    #[serde(default)]
8150    pub enabled: bool,
8151
8152    /// Enable fraud concealment co-occurrence patterns.
8153    #[serde(default = "default_true_val")]
8154    pub fraud_concealment: bool,
8155
8156    /// Enable error cascade patterns.
8157    #[serde(default = "default_true_val")]
8158    pub error_cascade: bool,
8159
8160    /// Enable temporal clustering (period-end spikes).
8161    #[serde(default = "default_true_val")]
8162    pub temporal_clustering: bool,
8163
8164    /// Temporal clustering configuration.
8165    #[serde(default)]
8166    pub temporal_clustering_config: TemporalClusteringConfig,
8167
8168    /// Co-occurrence patterns.
8169    #[serde(default)]
8170    pub co_occurrence_patterns: Vec<CoOccurrencePatternConfig>,
8171}
8172
8173impl Default for CorrelatedInjectionConfig {
8174    fn default() -> Self {
8175        Self {
8176            enabled: false,
8177            fraud_concealment: true,
8178            error_cascade: true,
8179            temporal_clustering: true,
8180            temporal_clustering_config: TemporalClusteringConfig::default(),
8181            co_occurrence_patterns: Vec::new(),
8182        }
8183    }
8184}
8185
8186/// Temporal clustering configuration.
8187#[derive(Debug, Clone, Serialize, Deserialize)]
8188pub struct TemporalClusteringConfig {
8189    /// Period-end error multiplier.
8190    #[serde(default = "default_period_end_multiplier")]
8191    pub period_end_multiplier: f64,
8192
8193    /// Number of business days before period end to apply multiplier.
8194    #[serde(default = "default_period_end_days")]
8195    pub period_end_days: u32,
8196
8197    /// Quarter-end additional multiplier.
8198    #[serde(default = "default_quarter_end_multiplier")]
8199    pub quarter_end_multiplier: f64,
8200
8201    /// Year-end additional multiplier.
8202    #[serde(default = "default_year_end_multiplier")]
8203    pub year_end_multiplier: f64,
8204}
8205
8206fn default_period_end_multiplier() -> f64 {
8207    2.5
8208}
8209fn default_period_end_days() -> u32 {
8210    5
8211}
8212fn default_quarter_end_multiplier() -> f64 {
8213    1.5
8214}
8215fn default_year_end_multiplier() -> f64 {
8216    2.0
8217}
8218
8219impl Default for TemporalClusteringConfig {
8220    fn default() -> Self {
8221        Self {
8222            period_end_multiplier: default_period_end_multiplier(),
8223            period_end_days: default_period_end_days(),
8224            quarter_end_multiplier: default_quarter_end_multiplier(),
8225            year_end_multiplier: default_year_end_multiplier(),
8226        }
8227    }
8228}
8229
8230/// Co-occurrence pattern configuration.
8231#[derive(Debug, Clone, Serialize, Deserialize)]
8232pub struct CoOccurrencePatternConfig {
8233    /// Pattern name.
8234    pub name: String,
8235
8236    /// Primary anomaly type that triggers the pattern.
8237    pub primary_type: String,
8238
8239    /// Correlated anomalies.
8240    pub correlated: Vec<CorrelatedAnomalyConfig>,
8241}
8242
8243/// Correlated anomaly configuration.
8244#[derive(Debug, Clone, Serialize, Deserialize)]
8245pub struct CorrelatedAnomalyConfig {
8246    /// Anomaly type.
8247    pub anomaly_type: String,
8248
8249    /// Probability of occurrence (0.0 to 1.0).
8250    pub probability: f64,
8251
8252    /// Minimum lag in days.
8253    pub lag_days_min: i32,
8254
8255    /// Maximum lag in days.
8256    pub lag_days_max: i32,
8257}
8258
8259/// Near-miss generation configuration.
8260#[derive(Debug, Clone, Serialize, Deserialize)]
8261pub struct NearMissConfig {
8262    /// Enable near-miss generation.
8263    #[serde(default)]
8264    pub enabled: bool,
8265
8266    /// Proportion of "anomalies" that are actually near-misses (0.0 to 1.0).
8267    #[serde(default = "default_near_miss_proportion")]
8268    pub proportion: f64,
8269
8270    /// Enable near-duplicate pattern.
8271    #[serde(default = "default_true_val")]
8272    pub near_duplicate: bool,
8273
8274    /// Near-duplicate date difference range in days.
8275    #[serde(default)]
8276    pub near_duplicate_days: NearDuplicateDaysConfig,
8277
8278    /// Enable threshold proximity pattern.
8279    #[serde(default = "default_true_val")]
8280    pub threshold_proximity: bool,
8281
8282    /// Threshold proximity range (e.g., 0.90-0.99 of threshold).
8283    #[serde(default)]
8284    pub threshold_proximity_range: ThresholdProximityRangeConfig,
8285
8286    /// Enable unusual but legitimate patterns.
8287    #[serde(default = "default_true_val")]
8288    pub unusual_legitimate: bool,
8289
8290    /// Types of unusual legitimate patterns to generate.
8291    #[serde(default = "default_unusual_legitimate_types")]
8292    pub unusual_legitimate_types: Vec<String>,
8293
8294    /// Enable corrected error patterns.
8295    #[serde(default = "default_true_val")]
8296    pub corrected_errors: bool,
8297
8298    /// Corrected error correction lag range in days.
8299    #[serde(default)]
8300    pub corrected_error_lag: CorrectedErrorLagConfig,
8301}
8302
8303fn default_near_miss_proportion() -> f64 {
8304    0.30
8305}
8306
8307fn default_unusual_legitimate_types() -> Vec<String> {
8308    vec![
8309        "year_end_bonus".to_string(),
8310        "contract_prepayment".to_string(),
8311        "insurance_claim".to_string(),
8312        "settlement_payment".to_string(),
8313    ]
8314}
8315
8316impl Default for NearMissConfig {
8317    fn default() -> Self {
8318        Self {
8319            enabled: false,
8320            proportion: default_near_miss_proportion(),
8321            near_duplicate: true,
8322            near_duplicate_days: NearDuplicateDaysConfig::default(),
8323            threshold_proximity: true,
8324            threshold_proximity_range: ThresholdProximityRangeConfig::default(),
8325            unusual_legitimate: true,
8326            unusual_legitimate_types: default_unusual_legitimate_types(),
8327            corrected_errors: true,
8328            corrected_error_lag: CorrectedErrorLagConfig::default(),
8329        }
8330    }
8331}
8332
8333/// Near-duplicate days configuration.
8334#[derive(Debug, Clone, Serialize, Deserialize)]
8335pub struct NearDuplicateDaysConfig {
8336    /// Minimum days apart.
8337    #[serde(default = "default_near_duplicate_min")]
8338    pub min: u32,
8339
8340    /// Maximum days apart.
8341    #[serde(default = "default_near_duplicate_max")]
8342    pub max: u32,
8343}
8344
8345fn default_near_duplicate_min() -> u32 {
8346    1
8347}
8348fn default_near_duplicate_max() -> u32 {
8349    3
8350}
8351
8352impl Default for NearDuplicateDaysConfig {
8353    fn default() -> Self {
8354        Self {
8355            min: default_near_duplicate_min(),
8356            max: default_near_duplicate_max(),
8357        }
8358    }
8359}
8360
8361/// Threshold proximity range configuration.
8362#[derive(Debug, Clone, Serialize, Deserialize)]
8363pub struct ThresholdProximityRangeConfig {
8364    /// Minimum proximity (e.g., 0.90 = 90% of threshold).
8365    #[serde(default = "default_threshold_proximity_min")]
8366    pub min: f64,
8367
8368    /// Maximum proximity (e.g., 0.99 = 99% of threshold).
8369    #[serde(default = "default_threshold_proximity_max")]
8370    pub max: f64,
8371}
8372
8373fn default_threshold_proximity_min() -> f64 {
8374    0.90
8375}
8376fn default_threshold_proximity_max() -> f64 {
8377    0.99
8378}
8379
8380impl Default for ThresholdProximityRangeConfig {
8381    fn default() -> Self {
8382        Self {
8383            min: default_threshold_proximity_min(),
8384            max: default_threshold_proximity_max(),
8385        }
8386    }
8387}
8388
8389/// Corrected error lag configuration.
8390#[derive(Debug, Clone, Serialize, Deserialize)]
8391pub struct CorrectedErrorLagConfig {
8392    /// Minimum correction lag in days.
8393    #[serde(default = "default_corrected_error_lag_min")]
8394    pub min: u32,
8395
8396    /// Maximum correction lag in days.
8397    #[serde(default = "default_corrected_error_lag_max")]
8398    pub max: u32,
8399}
8400
8401fn default_corrected_error_lag_min() -> u32 {
8402    1
8403}
8404fn default_corrected_error_lag_max() -> u32 {
8405    5
8406}
8407
8408impl Default for CorrectedErrorLagConfig {
8409    fn default() -> Self {
8410        Self {
8411            min: default_corrected_error_lag_min(),
8412            max: default_corrected_error_lag_max(),
8413        }
8414    }
8415}
8416
8417/// Detection difficulty classification configuration.
8418#[derive(Debug, Clone, Serialize, Deserialize)]
8419pub struct DifficultyClassificationConfig {
8420    /// Enable detection difficulty classification.
8421    #[serde(default)]
8422    pub enabled: bool,
8423
8424    /// Target distribution of difficulty levels.
8425    #[serde(default)]
8426    pub target_distribution: DifficultyDistributionConfig,
8427}
8428
8429impl Default for DifficultyClassificationConfig {
8430    fn default() -> Self {
8431        Self {
8432            enabled: true,
8433            target_distribution: DifficultyDistributionConfig::default(),
8434        }
8435    }
8436}
8437
8438/// Target distribution of detection difficulty levels.
8439#[derive(Debug, Clone, Serialize, Deserialize)]
8440pub struct DifficultyDistributionConfig {
8441    /// Proportion of trivial anomalies (expected 99% detection).
8442    #[serde(default = "default_difficulty_trivial")]
8443    pub trivial: f64,
8444
8445    /// Proportion of easy anomalies (expected 90% detection).
8446    #[serde(default = "default_difficulty_easy")]
8447    pub easy: f64,
8448
8449    /// Proportion of moderate anomalies (expected 70% detection).
8450    #[serde(default = "default_difficulty_moderate")]
8451    pub moderate: f64,
8452
8453    /// Proportion of hard anomalies (expected 40% detection).
8454    #[serde(default = "default_difficulty_hard")]
8455    pub hard: f64,
8456
8457    /// Proportion of expert anomalies (expected 15% detection).
8458    #[serde(default = "default_difficulty_expert")]
8459    pub expert: f64,
8460}
8461
8462fn default_difficulty_trivial() -> f64 {
8463    0.15
8464}
8465fn default_difficulty_easy() -> f64 {
8466    0.25
8467}
8468fn default_difficulty_moderate() -> f64 {
8469    0.30
8470}
8471fn default_difficulty_hard() -> f64 {
8472    0.20
8473}
8474fn default_difficulty_expert() -> f64 {
8475    0.10
8476}
8477
8478impl Default for DifficultyDistributionConfig {
8479    fn default() -> Self {
8480        Self {
8481            trivial: default_difficulty_trivial(),
8482            easy: default_difficulty_easy(),
8483            moderate: default_difficulty_moderate(),
8484            hard: default_difficulty_hard(),
8485            expert: default_difficulty_expert(),
8486        }
8487    }
8488}
8489
8490/// Context-aware injection configuration.
8491#[derive(Debug, Clone, Serialize, Deserialize, Default)]
8492pub struct ContextAwareConfig {
8493    /// Enable context-aware injection.
8494    #[serde(default)]
8495    pub enabled: bool,
8496
8497    /// Vendor-specific anomaly rules.
8498    #[serde(default)]
8499    pub vendor_rules: VendorAnomalyRulesConfig,
8500
8501    /// Employee-specific anomaly rules.
8502    #[serde(default)]
8503    pub employee_rules: EmployeeAnomalyRulesConfig,
8504
8505    /// Account-specific anomaly rules.
8506    #[serde(default)]
8507    pub account_rules: AccountAnomalyRulesConfig,
8508
8509    /// Behavioral baseline configuration.
8510    #[serde(default)]
8511    pub behavioral_baseline: BehavioralBaselineConfig,
8512}
8513
8514/// Vendor-specific anomaly rules configuration.
8515#[derive(Debug, Clone, Serialize, Deserialize)]
8516pub struct VendorAnomalyRulesConfig {
8517    /// Error rate multiplier for new vendors (< threshold days).
8518    #[serde(default = "default_new_vendor_multiplier")]
8519    pub new_vendor_error_multiplier: f64,
8520
8521    /// Days threshold for "new" vendor classification.
8522    #[serde(default = "default_new_vendor_threshold")]
8523    pub new_vendor_threshold_days: u32,
8524
8525    /// Error rate multiplier for international vendors.
8526    #[serde(default = "default_international_multiplier")]
8527    pub international_error_multiplier: f64,
8528
8529    /// Strategic vendor anomaly types (may differ from general vendors).
8530    #[serde(default = "default_strategic_vendor_types")]
8531    pub strategic_vendor_anomaly_types: Vec<String>,
8532}
8533
8534fn default_new_vendor_multiplier() -> f64 {
8535    2.5
8536}
8537fn default_new_vendor_threshold() -> u32 {
8538    90
8539}
8540fn default_international_multiplier() -> f64 {
8541    1.5
8542}
8543fn default_strategic_vendor_types() -> Vec<String> {
8544    vec![
8545        "pricing_dispute".to_string(),
8546        "contract_violation".to_string(),
8547    ]
8548}
8549
8550impl Default for VendorAnomalyRulesConfig {
8551    fn default() -> Self {
8552        Self {
8553            new_vendor_error_multiplier: default_new_vendor_multiplier(),
8554            new_vendor_threshold_days: default_new_vendor_threshold(),
8555            international_error_multiplier: default_international_multiplier(),
8556            strategic_vendor_anomaly_types: default_strategic_vendor_types(),
8557        }
8558    }
8559}
8560
8561/// Employee-specific anomaly rules configuration.
8562#[derive(Debug, Clone, Serialize, Deserialize)]
8563pub struct EmployeeAnomalyRulesConfig {
8564    /// Error rate for new employees (< threshold days).
8565    #[serde(default = "default_new_employee_rate")]
8566    pub new_employee_error_rate: f64,
8567
8568    /// Days threshold for "new" employee classification.
8569    #[serde(default = "default_new_employee_threshold")]
8570    pub new_employee_threshold_days: u32,
8571
8572    /// Transaction volume threshold for fatigue errors.
8573    #[serde(default = "default_volume_fatigue_threshold")]
8574    pub volume_fatigue_threshold: u32,
8575
8576    /// Error rate multiplier when primary approver is absent.
8577    #[serde(default = "default_coverage_multiplier")]
8578    pub coverage_error_multiplier: f64,
8579}
8580
8581fn default_new_employee_rate() -> f64 {
8582    0.05
8583}
8584fn default_new_employee_threshold() -> u32 {
8585    180
8586}
8587fn default_volume_fatigue_threshold() -> u32 {
8588    50
8589}
8590fn default_coverage_multiplier() -> f64 {
8591    1.8
8592}
8593
8594impl Default for EmployeeAnomalyRulesConfig {
8595    fn default() -> Self {
8596        Self {
8597            new_employee_error_rate: default_new_employee_rate(),
8598            new_employee_threshold_days: default_new_employee_threshold(),
8599            volume_fatigue_threshold: default_volume_fatigue_threshold(),
8600            coverage_error_multiplier: default_coverage_multiplier(),
8601        }
8602    }
8603}
8604
8605/// Account-specific anomaly rules configuration.
8606#[derive(Debug, Clone, Serialize, Deserialize)]
8607pub struct AccountAnomalyRulesConfig {
8608    /// Error rate multiplier for high-risk accounts.
8609    #[serde(default = "default_high_risk_multiplier")]
8610    pub high_risk_account_multiplier: f64,
8611
8612    /// Account codes considered high-risk.
8613    #[serde(default = "default_high_risk_accounts")]
8614    pub high_risk_accounts: Vec<String>,
8615
8616    /// Error rate multiplier for suspense accounts.
8617    #[serde(default = "default_suspense_multiplier")]
8618    pub suspense_account_multiplier: f64,
8619
8620    /// Account codes considered suspense accounts.
8621    #[serde(default = "default_suspense_accounts")]
8622    pub suspense_accounts: Vec<String>,
8623
8624    /// Error rate multiplier for intercompany accounts.
8625    #[serde(default = "default_intercompany_multiplier")]
8626    pub intercompany_account_multiplier: f64,
8627}
8628
8629fn default_high_risk_multiplier() -> f64 {
8630    2.0
8631}
8632fn default_high_risk_accounts() -> Vec<String> {
8633    vec![
8634        "1100".to_string(), // AR Control
8635        "2000".to_string(), // AP Control
8636        "3000".to_string(), // Cash
8637    ]
8638}
8639fn default_suspense_multiplier() -> f64 {
8640    3.0
8641}
8642fn default_suspense_accounts() -> Vec<String> {
8643    vec!["9999".to_string(), "9998".to_string()]
8644}
8645fn default_intercompany_multiplier() -> f64 {
8646    1.5
8647}
8648
8649impl Default for AccountAnomalyRulesConfig {
8650    fn default() -> Self {
8651        Self {
8652            high_risk_account_multiplier: default_high_risk_multiplier(),
8653            high_risk_accounts: default_high_risk_accounts(),
8654            suspense_account_multiplier: default_suspense_multiplier(),
8655            suspense_accounts: default_suspense_accounts(),
8656            intercompany_account_multiplier: default_intercompany_multiplier(),
8657        }
8658    }
8659}
8660
8661/// Behavioral baseline configuration.
8662#[derive(Debug, Clone, Serialize, Deserialize)]
8663pub struct BehavioralBaselineConfig {
8664    /// Enable behavioral baseline tracking.
8665    #[serde(default)]
8666    pub enabled: bool,
8667
8668    /// Number of days to build baseline from.
8669    #[serde(default = "default_baseline_period")]
8670    pub baseline_period_days: u32,
8671
8672    /// Standard deviation threshold for amount anomalies.
8673    #[serde(default = "default_deviation_threshold")]
8674    pub deviation_threshold_std: f64,
8675
8676    /// Standard deviation threshold for frequency anomalies.
8677    #[serde(default = "default_frequency_deviation")]
8678    pub frequency_deviation_threshold: f64,
8679}
8680
8681fn default_baseline_period() -> u32 {
8682    90
8683}
8684fn default_deviation_threshold() -> f64 {
8685    3.0
8686}
8687fn default_frequency_deviation() -> f64 {
8688    2.0
8689}
8690
8691impl Default for BehavioralBaselineConfig {
8692    fn default() -> Self {
8693        Self {
8694            enabled: false,
8695            baseline_period_days: default_baseline_period(),
8696            deviation_threshold_std: default_deviation_threshold(),
8697            frequency_deviation_threshold: default_frequency_deviation(),
8698        }
8699    }
8700}
8701
8702/// Enhanced labeling configuration.
8703#[derive(Debug, Clone, Serialize, Deserialize)]
8704pub struct EnhancedLabelingConfig {
8705    /// Enable severity scoring.
8706    #[serde(default = "default_true_val")]
8707    pub severity_scoring: bool,
8708
8709    /// Enable difficulty classification.
8710    #[serde(default = "default_true_val")]
8711    pub difficulty_classification: bool,
8712
8713    /// Materiality thresholds for severity classification.
8714    #[serde(default)]
8715    pub materiality_thresholds: MaterialityThresholdsConfig,
8716}
8717
8718impl Default for EnhancedLabelingConfig {
8719    fn default() -> Self {
8720        Self {
8721            severity_scoring: true,
8722            difficulty_classification: true,
8723            materiality_thresholds: MaterialityThresholdsConfig::default(),
8724        }
8725    }
8726}
8727
8728/// Materiality thresholds configuration.
8729#[derive(Debug, Clone, Serialize, Deserialize)]
8730pub struct MaterialityThresholdsConfig {
8731    /// Threshold for trivial impact (as percentage of total).
8732    #[serde(default = "default_materiality_trivial")]
8733    pub trivial: f64,
8734
8735    /// Threshold for immaterial impact.
8736    #[serde(default = "default_materiality_immaterial")]
8737    pub immaterial: f64,
8738
8739    /// Threshold for material impact.
8740    #[serde(default = "default_materiality_material")]
8741    pub material: f64,
8742
8743    /// Threshold for highly material impact.
8744    #[serde(default = "default_materiality_highly_material")]
8745    pub highly_material: f64,
8746}
8747
8748fn default_materiality_trivial() -> f64 {
8749    0.001
8750}
8751fn default_materiality_immaterial() -> f64 {
8752    0.01
8753}
8754fn default_materiality_material() -> f64 {
8755    0.05
8756}
8757fn default_materiality_highly_material() -> f64 {
8758    0.10
8759}
8760
8761impl Default for MaterialityThresholdsConfig {
8762    fn default() -> Self {
8763        Self {
8764            trivial: default_materiality_trivial(),
8765            immaterial: default_materiality_immaterial(),
8766            material: default_materiality_material(),
8767            highly_material: default_materiality_highly_material(),
8768        }
8769    }
8770}
8771
8772// =============================================================================
8773// Industry-Specific Configuration
8774// =============================================================================
8775
8776/// Industry-specific transaction and anomaly generation configuration.
8777///
8778/// This configuration enables generation of industry-authentic:
8779/// - Transaction types with appropriate terminology
8780/// - Master data (BOM, routings, clinical codes, etc.)
8781/// - Industry-specific anomaly patterns
8782/// - Regulatory framework compliance
8783#[derive(Debug, Clone, Serialize, Deserialize, Default)]
8784pub struct IndustrySpecificConfig {
8785    /// Enable industry-specific generation.
8786    #[serde(default)]
8787    pub enabled: bool,
8788
8789    /// Manufacturing industry settings.
8790    #[serde(default)]
8791    pub manufacturing: ManufacturingConfig,
8792
8793    /// Retail industry settings.
8794    #[serde(default)]
8795    pub retail: RetailConfig,
8796
8797    /// Healthcare industry settings.
8798    #[serde(default)]
8799    pub healthcare: HealthcareConfig,
8800
8801    /// Technology industry settings.
8802    #[serde(default)]
8803    pub technology: TechnologyConfig,
8804
8805    /// Financial services industry settings.
8806    #[serde(default)]
8807    pub financial_services: FinancialServicesConfig,
8808
8809    /// Professional services industry settings.
8810    #[serde(default)]
8811    pub professional_services: ProfessionalServicesConfig,
8812}
8813
8814/// Manufacturing industry configuration.
8815#[derive(Debug, Clone, Serialize, Deserialize)]
8816pub struct ManufacturingConfig {
8817    /// Enable manufacturing-specific generation.
8818    #[serde(default)]
8819    pub enabled: bool,
8820
8821    /// Bill of Materials depth (typical: 3-7).
8822    #[serde(default = "default_bom_depth")]
8823    pub bom_depth: u32,
8824
8825    /// Whether to use just-in-time inventory.
8826    #[serde(default)]
8827    pub just_in_time: bool,
8828
8829    /// Production order types to generate.
8830    #[serde(default = "default_production_order_types")]
8831    pub production_order_types: Vec<String>,
8832
8833    /// Quality framework (ISO_9001, Six_Sigma, etc.).
8834    #[serde(default)]
8835    pub quality_framework: Option<String>,
8836
8837    /// Number of supplier tiers to model (1-3).
8838    #[serde(default = "default_supplier_tiers")]
8839    pub supplier_tiers: u32,
8840
8841    /// Standard cost update frequency.
8842    #[serde(default = "default_cost_frequency")]
8843    pub standard_cost_frequency: String,
8844
8845    /// Target yield rate (0.95-0.99 typical).
8846    #[serde(default = "default_yield_rate")]
8847    pub target_yield_rate: f64,
8848
8849    /// Scrap percentage threshold for alerts.
8850    #[serde(default = "default_scrap_threshold")]
8851    pub scrap_alert_threshold: f64,
8852
8853    /// Manufacturing anomaly injection rates.
8854    #[serde(default)]
8855    pub anomaly_rates: ManufacturingAnomalyRates,
8856}
8857
8858fn default_bom_depth() -> u32 {
8859    4
8860}
8861
8862fn default_production_order_types() -> Vec<String> {
8863    vec![
8864        "standard".to_string(),
8865        "rework".to_string(),
8866        "prototype".to_string(),
8867    ]
8868}
8869
8870fn default_supplier_tiers() -> u32 {
8871    2
8872}
8873
8874fn default_cost_frequency() -> String {
8875    "quarterly".to_string()
8876}
8877
8878fn default_yield_rate() -> f64 {
8879    0.97
8880}
8881
8882fn default_scrap_threshold() -> f64 {
8883    0.03
8884}
8885
8886impl Default for ManufacturingConfig {
8887    fn default() -> Self {
8888        Self {
8889            enabled: false,
8890            bom_depth: default_bom_depth(),
8891            just_in_time: false,
8892            production_order_types: default_production_order_types(),
8893            quality_framework: Some("ISO_9001".to_string()),
8894            supplier_tiers: default_supplier_tiers(),
8895            standard_cost_frequency: default_cost_frequency(),
8896            target_yield_rate: default_yield_rate(),
8897            scrap_alert_threshold: default_scrap_threshold(),
8898            anomaly_rates: ManufacturingAnomalyRates::default(),
8899        }
8900    }
8901}
8902
8903/// Manufacturing anomaly injection rates.
8904#[derive(Debug, Clone, Serialize, Deserialize)]
8905pub struct ManufacturingAnomalyRates {
8906    /// Yield manipulation rate.
8907    #[serde(default = "default_mfg_yield_rate")]
8908    pub yield_manipulation: f64,
8909
8910    /// Labor misallocation rate.
8911    #[serde(default = "default_mfg_labor_rate")]
8912    pub labor_misallocation: f64,
8913
8914    /// Phantom production rate.
8915    #[serde(default = "default_mfg_phantom_rate")]
8916    pub phantom_production: f64,
8917
8918    /// Standard cost manipulation rate.
8919    #[serde(default = "default_mfg_cost_rate")]
8920    pub standard_cost_manipulation: f64,
8921
8922    /// Inventory fraud rate.
8923    #[serde(default = "default_mfg_inventory_rate")]
8924    pub inventory_fraud: f64,
8925}
8926
8927fn default_mfg_yield_rate() -> f64 {
8928    0.015
8929}
8930
8931fn default_mfg_labor_rate() -> f64 {
8932    0.02
8933}
8934
8935fn default_mfg_phantom_rate() -> f64 {
8936    0.005
8937}
8938
8939fn default_mfg_cost_rate() -> f64 {
8940    0.01
8941}
8942
8943fn default_mfg_inventory_rate() -> f64 {
8944    0.008
8945}
8946
8947impl Default for ManufacturingAnomalyRates {
8948    fn default() -> Self {
8949        Self {
8950            yield_manipulation: default_mfg_yield_rate(),
8951            labor_misallocation: default_mfg_labor_rate(),
8952            phantom_production: default_mfg_phantom_rate(),
8953            standard_cost_manipulation: default_mfg_cost_rate(),
8954            inventory_fraud: default_mfg_inventory_rate(),
8955        }
8956    }
8957}
8958
8959/// Retail industry configuration.
8960#[derive(Debug, Clone, Serialize, Deserialize)]
8961pub struct RetailConfig {
8962    /// Enable retail-specific generation.
8963    #[serde(default)]
8964    pub enabled: bool,
8965
8966    /// Store type distribution.
8967    #[serde(default)]
8968    pub store_types: RetailStoreTypeConfig,
8969
8970    /// Average daily transactions per store.
8971    #[serde(default = "default_retail_daily_txns")]
8972    pub avg_daily_transactions: u32,
8973
8974    /// Enable loss prevention tracking.
8975    #[serde(default = "default_true")]
8976    pub loss_prevention: bool,
8977
8978    /// Shrinkage rate (0.01-0.03 typical).
8979    #[serde(default = "default_shrinkage_rate")]
8980    pub shrinkage_rate: f64,
8981
8982    /// Retail anomaly injection rates.
8983    #[serde(default)]
8984    pub anomaly_rates: RetailAnomalyRates,
8985}
8986
8987fn default_retail_daily_txns() -> u32 {
8988    500
8989}
8990
8991fn default_shrinkage_rate() -> f64 {
8992    0.015
8993}
8994
8995impl Default for RetailConfig {
8996    fn default() -> Self {
8997        Self {
8998            enabled: false,
8999            store_types: RetailStoreTypeConfig::default(),
9000            avg_daily_transactions: default_retail_daily_txns(),
9001            loss_prevention: true,
9002            shrinkage_rate: default_shrinkage_rate(),
9003            anomaly_rates: RetailAnomalyRates::default(),
9004        }
9005    }
9006}
9007
9008/// Retail store type distribution.
9009#[derive(Debug, Clone, Serialize, Deserialize)]
9010pub struct RetailStoreTypeConfig {
9011    /// Percentage of flagship stores.
9012    #[serde(default = "default_flagship_pct")]
9013    pub flagship: f64,
9014
9015    /// Percentage of regional stores.
9016    #[serde(default = "default_regional_pct")]
9017    pub regional: f64,
9018
9019    /// Percentage of outlet stores.
9020    #[serde(default = "default_outlet_pct")]
9021    pub outlet: f64,
9022
9023    /// Percentage of e-commerce.
9024    #[serde(default = "default_ecommerce_pct")]
9025    pub ecommerce: f64,
9026}
9027
9028fn default_flagship_pct() -> f64 {
9029    0.10
9030}
9031
9032fn default_regional_pct() -> f64 {
9033    0.50
9034}
9035
9036fn default_outlet_pct() -> f64 {
9037    0.25
9038}
9039
9040fn default_ecommerce_pct() -> f64 {
9041    0.15
9042}
9043
9044impl Default for RetailStoreTypeConfig {
9045    fn default() -> Self {
9046        Self {
9047            flagship: default_flagship_pct(),
9048            regional: default_regional_pct(),
9049            outlet: default_outlet_pct(),
9050            ecommerce: default_ecommerce_pct(),
9051        }
9052    }
9053}
9054
9055/// Retail anomaly injection rates.
9056#[derive(Debug, Clone, Serialize, Deserialize)]
9057pub struct RetailAnomalyRates {
9058    /// Sweethearting rate.
9059    #[serde(default = "default_sweethearting_rate")]
9060    pub sweethearting: f64,
9061
9062    /// Skimming rate.
9063    #[serde(default = "default_skimming_rate")]
9064    pub skimming: f64,
9065
9066    /// Refund fraud rate.
9067    #[serde(default = "default_refund_fraud_rate")]
9068    pub refund_fraud: f64,
9069
9070    /// Void abuse rate.
9071    #[serde(default = "default_void_abuse_rate")]
9072    pub void_abuse: f64,
9073
9074    /// Gift card fraud rate.
9075    #[serde(default = "default_gift_card_rate")]
9076    pub gift_card_fraud: f64,
9077
9078    /// Vendor kickback rate.
9079    #[serde(default = "default_retail_kickback_rate")]
9080    pub vendor_kickback: f64,
9081}
9082
9083fn default_sweethearting_rate() -> f64 {
9084    0.02
9085}
9086
9087fn default_skimming_rate() -> f64 {
9088    0.005
9089}
9090
9091fn default_refund_fraud_rate() -> f64 {
9092    0.015
9093}
9094
9095fn default_void_abuse_rate() -> f64 {
9096    0.01
9097}
9098
9099fn default_gift_card_rate() -> f64 {
9100    0.008
9101}
9102
9103fn default_retail_kickback_rate() -> f64 {
9104    0.003
9105}
9106
9107impl Default for RetailAnomalyRates {
9108    fn default() -> Self {
9109        Self {
9110            sweethearting: default_sweethearting_rate(),
9111            skimming: default_skimming_rate(),
9112            refund_fraud: default_refund_fraud_rate(),
9113            void_abuse: default_void_abuse_rate(),
9114            gift_card_fraud: default_gift_card_rate(),
9115            vendor_kickback: default_retail_kickback_rate(),
9116        }
9117    }
9118}
9119
9120/// Healthcare industry configuration.
9121#[derive(Debug, Clone, Serialize, Deserialize)]
9122pub struct HealthcareConfig {
9123    /// Enable healthcare-specific generation.
9124    #[serde(default)]
9125    pub enabled: bool,
9126
9127    /// Healthcare facility type.
9128    #[serde(default = "default_facility_type")]
9129    pub facility_type: String,
9130
9131    /// Payer mix distribution.
9132    #[serde(default)]
9133    pub payer_mix: HealthcarePayerMix,
9134
9135    /// Coding systems enabled.
9136    #[serde(default)]
9137    pub coding_systems: HealthcareCodingSystems,
9138
9139    /// Healthcare compliance settings.
9140    #[serde(default)]
9141    pub compliance: HealthcareComplianceConfig,
9142
9143    /// Average daily encounters.
9144    #[serde(default = "default_daily_encounters")]
9145    pub avg_daily_encounters: u32,
9146
9147    /// Average charges per encounter.
9148    #[serde(default = "default_charges_per_encounter")]
9149    pub avg_charges_per_encounter: u32,
9150
9151    /// Denial rate (0.0-1.0).
9152    #[serde(default = "default_hc_denial_rate")]
9153    pub denial_rate: f64,
9154
9155    /// Bad debt rate (0.0-1.0).
9156    #[serde(default = "default_hc_bad_debt_rate")]
9157    pub bad_debt_rate: f64,
9158
9159    /// Charity care rate (0.0-1.0).
9160    #[serde(default = "default_hc_charity_care_rate")]
9161    pub charity_care_rate: f64,
9162
9163    /// Healthcare anomaly injection rates.
9164    #[serde(default)]
9165    pub anomaly_rates: HealthcareAnomalyRates,
9166}
9167
9168fn default_facility_type() -> String {
9169    "hospital".to_string()
9170}
9171
9172fn default_daily_encounters() -> u32 {
9173    150
9174}
9175
9176fn default_charges_per_encounter() -> u32 {
9177    8
9178}
9179
9180fn default_hc_denial_rate() -> f64 {
9181    0.05
9182}
9183
9184fn default_hc_bad_debt_rate() -> f64 {
9185    0.03
9186}
9187
9188fn default_hc_charity_care_rate() -> f64 {
9189    0.02
9190}
9191
9192impl Default for HealthcareConfig {
9193    fn default() -> Self {
9194        Self {
9195            enabled: false,
9196            facility_type: default_facility_type(),
9197            payer_mix: HealthcarePayerMix::default(),
9198            coding_systems: HealthcareCodingSystems::default(),
9199            compliance: HealthcareComplianceConfig::default(),
9200            avg_daily_encounters: default_daily_encounters(),
9201            avg_charges_per_encounter: default_charges_per_encounter(),
9202            denial_rate: default_hc_denial_rate(),
9203            bad_debt_rate: default_hc_bad_debt_rate(),
9204            charity_care_rate: default_hc_charity_care_rate(),
9205            anomaly_rates: HealthcareAnomalyRates::default(),
9206        }
9207    }
9208}
9209
9210/// Healthcare payer mix distribution.
9211#[derive(Debug, Clone, Serialize, Deserialize)]
9212pub struct HealthcarePayerMix {
9213    /// Medicare percentage.
9214    #[serde(default = "default_medicare_pct")]
9215    pub medicare: f64,
9216
9217    /// Medicaid percentage.
9218    #[serde(default = "default_medicaid_pct")]
9219    pub medicaid: f64,
9220
9221    /// Commercial insurance percentage.
9222    #[serde(default = "default_commercial_pct")]
9223    pub commercial: f64,
9224
9225    /// Self-pay percentage.
9226    #[serde(default = "default_self_pay_pct")]
9227    pub self_pay: f64,
9228}
9229
9230fn default_medicare_pct() -> f64 {
9231    0.40
9232}
9233
9234fn default_medicaid_pct() -> f64 {
9235    0.20
9236}
9237
9238fn default_commercial_pct() -> f64 {
9239    0.30
9240}
9241
9242fn default_self_pay_pct() -> f64 {
9243    0.10
9244}
9245
9246impl Default for HealthcarePayerMix {
9247    fn default() -> Self {
9248        Self {
9249            medicare: default_medicare_pct(),
9250            medicaid: default_medicaid_pct(),
9251            commercial: default_commercial_pct(),
9252            self_pay: default_self_pay_pct(),
9253        }
9254    }
9255}
9256
9257/// Healthcare coding systems configuration.
9258#[derive(Debug, Clone, Serialize, Deserialize)]
9259pub struct HealthcareCodingSystems {
9260    /// Enable ICD-10 diagnosis coding.
9261    #[serde(default = "default_true")]
9262    pub icd10: bool,
9263
9264    /// Enable CPT procedure coding.
9265    #[serde(default = "default_true")]
9266    pub cpt: bool,
9267
9268    /// Enable DRG grouping.
9269    #[serde(default = "default_true")]
9270    pub drg: bool,
9271
9272    /// Enable HCPCS Level II coding.
9273    #[serde(default = "default_true")]
9274    pub hcpcs: bool,
9275
9276    /// Enable revenue codes.
9277    #[serde(default = "default_true")]
9278    pub revenue_codes: bool,
9279}
9280
9281impl Default for HealthcareCodingSystems {
9282    fn default() -> Self {
9283        Self {
9284            icd10: true,
9285            cpt: true,
9286            drg: true,
9287            hcpcs: true,
9288            revenue_codes: true,
9289        }
9290    }
9291}
9292
9293/// Healthcare compliance configuration.
9294#[derive(Debug, Clone, Serialize, Deserialize)]
9295pub struct HealthcareComplianceConfig {
9296    /// Enable HIPAA compliance.
9297    #[serde(default = "default_true")]
9298    pub hipaa: bool,
9299
9300    /// Enable Stark Law compliance.
9301    #[serde(default = "default_true")]
9302    pub stark_law: bool,
9303
9304    /// Enable Anti-Kickback Statute compliance.
9305    #[serde(default = "default_true")]
9306    pub anti_kickback: bool,
9307
9308    /// Enable False Claims Act compliance.
9309    #[serde(default = "default_true")]
9310    pub false_claims_act: bool,
9311
9312    /// Enable EMTALA compliance (for hospitals).
9313    #[serde(default = "default_true")]
9314    pub emtala: bool,
9315}
9316
9317impl Default for HealthcareComplianceConfig {
9318    fn default() -> Self {
9319        Self {
9320            hipaa: true,
9321            stark_law: true,
9322            anti_kickback: true,
9323            false_claims_act: true,
9324            emtala: true,
9325        }
9326    }
9327}
9328
9329/// Healthcare anomaly injection rates.
9330#[derive(Debug, Clone, Serialize, Deserialize)]
9331pub struct HealthcareAnomalyRates {
9332    /// Upcoding rate.
9333    #[serde(default = "default_upcoding_rate")]
9334    pub upcoding: f64,
9335
9336    /// Unbundling rate.
9337    #[serde(default = "default_unbundling_rate")]
9338    pub unbundling: f64,
9339
9340    /// Phantom billing rate.
9341    #[serde(default = "default_phantom_billing_rate")]
9342    pub phantom_billing: f64,
9343
9344    /// Kickback rate.
9345    #[serde(default = "default_healthcare_kickback_rate")]
9346    pub kickbacks: f64,
9347
9348    /// Duplicate billing rate.
9349    #[serde(default = "default_duplicate_billing_rate")]
9350    pub duplicate_billing: f64,
9351
9352    /// Medical necessity abuse rate.
9353    #[serde(default = "default_med_necessity_rate")]
9354    pub medical_necessity_abuse: f64,
9355}
9356
9357fn default_upcoding_rate() -> f64 {
9358    0.02
9359}
9360
9361fn default_unbundling_rate() -> f64 {
9362    0.015
9363}
9364
9365fn default_phantom_billing_rate() -> f64 {
9366    0.005
9367}
9368
9369fn default_healthcare_kickback_rate() -> f64 {
9370    0.003
9371}
9372
9373fn default_duplicate_billing_rate() -> f64 {
9374    0.008
9375}
9376
9377fn default_med_necessity_rate() -> f64 {
9378    0.01
9379}
9380
9381impl Default for HealthcareAnomalyRates {
9382    fn default() -> Self {
9383        Self {
9384            upcoding: default_upcoding_rate(),
9385            unbundling: default_unbundling_rate(),
9386            phantom_billing: default_phantom_billing_rate(),
9387            kickbacks: default_healthcare_kickback_rate(),
9388            duplicate_billing: default_duplicate_billing_rate(),
9389            medical_necessity_abuse: default_med_necessity_rate(),
9390        }
9391    }
9392}
9393
9394/// Technology industry configuration.
9395#[derive(Debug, Clone, Serialize, Deserialize)]
9396pub struct TechnologyConfig {
9397    /// Enable technology-specific generation.
9398    #[serde(default)]
9399    pub enabled: bool,
9400
9401    /// Revenue model type.
9402    #[serde(default = "default_revenue_model")]
9403    pub revenue_model: String,
9404
9405    /// Subscription revenue percentage (for SaaS).
9406    #[serde(default = "default_subscription_pct")]
9407    pub subscription_revenue_pct: f64,
9408
9409    /// License revenue percentage.
9410    #[serde(default = "default_license_pct")]
9411    pub license_revenue_pct: f64,
9412
9413    /// Services revenue percentage.
9414    #[serde(default = "default_services_pct")]
9415    pub services_revenue_pct: f64,
9416
9417    /// R&D capitalization settings.
9418    #[serde(default)]
9419    pub rd_capitalization: RdCapitalizationConfig,
9420
9421    /// Technology anomaly injection rates.
9422    #[serde(default)]
9423    pub anomaly_rates: TechnologyAnomalyRates,
9424}
9425
9426fn default_revenue_model() -> String {
9427    "saas".to_string()
9428}
9429
9430fn default_subscription_pct() -> f64 {
9431    0.60
9432}
9433
9434fn default_license_pct() -> f64 {
9435    0.25
9436}
9437
9438fn default_services_pct() -> f64 {
9439    0.15
9440}
9441
9442impl Default for TechnologyConfig {
9443    fn default() -> Self {
9444        Self {
9445            enabled: false,
9446            revenue_model: default_revenue_model(),
9447            subscription_revenue_pct: default_subscription_pct(),
9448            license_revenue_pct: default_license_pct(),
9449            services_revenue_pct: default_services_pct(),
9450            rd_capitalization: RdCapitalizationConfig::default(),
9451            anomaly_rates: TechnologyAnomalyRates::default(),
9452        }
9453    }
9454}
9455
9456/// R&D capitalization configuration.
9457#[derive(Debug, Clone, Serialize, Deserialize)]
9458pub struct RdCapitalizationConfig {
9459    /// Enable R&D capitalization.
9460    #[serde(default = "default_true")]
9461    pub enabled: bool,
9462
9463    /// Capitalization rate (0.0-1.0).
9464    #[serde(default = "default_cap_rate")]
9465    pub capitalization_rate: f64,
9466
9467    /// Useful life in years.
9468    #[serde(default = "default_useful_life")]
9469    pub useful_life_years: u32,
9470}
9471
9472fn default_cap_rate() -> f64 {
9473    0.30
9474}
9475
9476fn default_useful_life() -> u32 {
9477    3
9478}
9479
9480impl Default for RdCapitalizationConfig {
9481    fn default() -> Self {
9482        Self {
9483            enabled: true,
9484            capitalization_rate: default_cap_rate(),
9485            useful_life_years: default_useful_life(),
9486        }
9487    }
9488}
9489
9490/// Technology anomaly injection rates.
9491#[derive(Debug, Clone, Serialize, Deserialize)]
9492pub struct TechnologyAnomalyRates {
9493    /// Premature revenue recognition rate.
9494    #[serde(default = "default_premature_rev_rate")]
9495    pub premature_revenue: f64,
9496
9497    /// Side letter abuse rate.
9498    #[serde(default = "default_side_letter_rate")]
9499    pub side_letter_abuse: f64,
9500
9501    /// Channel stuffing rate.
9502    #[serde(default = "default_channel_stuffing_rate")]
9503    pub channel_stuffing: f64,
9504
9505    /// Improper capitalization rate.
9506    #[serde(default = "default_improper_cap_rate")]
9507    pub improper_capitalization: f64,
9508}
9509
9510fn default_premature_rev_rate() -> f64 {
9511    0.015
9512}
9513
9514fn default_side_letter_rate() -> f64 {
9515    0.008
9516}
9517
9518fn default_channel_stuffing_rate() -> f64 {
9519    0.01
9520}
9521
9522fn default_improper_cap_rate() -> f64 {
9523    0.012
9524}
9525
9526impl Default for TechnologyAnomalyRates {
9527    fn default() -> Self {
9528        Self {
9529            premature_revenue: default_premature_rev_rate(),
9530            side_letter_abuse: default_side_letter_rate(),
9531            channel_stuffing: default_channel_stuffing_rate(),
9532            improper_capitalization: default_improper_cap_rate(),
9533        }
9534    }
9535}
9536
9537/// Financial services industry configuration.
9538#[derive(Debug, Clone, Serialize, Deserialize)]
9539pub struct FinancialServicesConfig {
9540    /// Enable financial services-specific generation.
9541    #[serde(default)]
9542    pub enabled: bool,
9543
9544    /// Financial institution type.
9545    #[serde(default = "default_fi_type")]
9546    pub institution_type: String,
9547
9548    /// Regulatory framework.
9549    #[serde(default = "default_fi_regulatory")]
9550    pub regulatory_framework: String,
9551
9552    /// Financial services anomaly injection rates.
9553    #[serde(default)]
9554    pub anomaly_rates: FinancialServicesAnomalyRates,
9555}
9556
9557fn default_fi_type() -> String {
9558    "commercial_bank".to_string()
9559}
9560
9561fn default_fi_regulatory() -> String {
9562    "us_banking".to_string()
9563}
9564
9565impl Default for FinancialServicesConfig {
9566    fn default() -> Self {
9567        Self {
9568            enabled: false,
9569            institution_type: default_fi_type(),
9570            regulatory_framework: default_fi_regulatory(),
9571            anomaly_rates: FinancialServicesAnomalyRates::default(),
9572        }
9573    }
9574}
9575
9576/// Financial services anomaly injection rates.
9577#[derive(Debug, Clone, Serialize, Deserialize)]
9578pub struct FinancialServicesAnomalyRates {
9579    /// Loan fraud rate.
9580    #[serde(default = "default_loan_fraud_rate")]
9581    pub loan_fraud: f64,
9582
9583    /// Trading fraud rate.
9584    #[serde(default = "default_trading_fraud_rate")]
9585    pub trading_fraud: f64,
9586
9587    /// Insurance fraud rate.
9588    #[serde(default = "default_insurance_fraud_rate")]
9589    pub insurance_fraud: f64,
9590
9591    /// Account manipulation rate.
9592    #[serde(default = "default_account_manip_rate")]
9593    pub account_manipulation: f64,
9594}
9595
9596fn default_loan_fraud_rate() -> f64 {
9597    0.01
9598}
9599
9600fn default_trading_fraud_rate() -> f64 {
9601    0.008
9602}
9603
9604fn default_insurance_fraud_rate() -> f64 {
9605    0.012
9606}
9607
9608fn default_account_manip_rate() -> f64 {
9609    0.005
9610}
9611
9612impl Default for FinancialServicesAnomalyRates {
9613    fn default() -> Self {
9614        Self {
9615            loan_fraud: default_loan_fraud_rate(),
9616            trading_fraud: default_trading_fraud_rate(),
9617            insurance_fraud: default_insurance_fraud_rate(),
9618            account_manipulation: default_account_manip_rate(),
9619        }
9620    }
9621}
9622
9623/// Professional services industry configuration.
9624#[derive(Debug, Clone, Serialize, Deserialize)]
9625pub struct ProfessionalServicesConfig {
9626    /// Enable professional services-specific generation.
9627    #[serde(default)]
9628    pub enabled: bool,
9629
9630    /// Firm type.
9631    #[serde(default = "default_firm_type")]
9632    pub firm_type: String,
9633
9634    /// Billing model.
9635    #[serde(default = "default_billing_model")]
9636    pub billing_model: String,
9637
9638    /// Average hourly rate.
9639    #[serde(default = "default_hourly_rate")]
9640    pub avg_hourly_rate: f64,
9641
9642    /// Trust account settings (for law firms).
9643    #[serde(default)]
9644    pub trust_accounting: TrustAccountingConfig,
9645
9646    /// Professional services anomaly injection rates.
9647    #[serde(default)]
9648    pub anomaly_rates: ProfessionalServicesAnomalyRates,
9649}
9650
9651fn default_firm_type() -> String {
9652    "consulting".to_string()
9653}
9654
9655fn default_billing_model() -> String {
9656    "time_and_materials".to_string()
9657}
9658
9659fn default_hourly_rate() -> f64 {
9660    250.0
9661}
9662
9663impl Default for ProfessionalServicesConfig {
9664    fn default() -> Self {
9665        Self {
9666            enabled: false,
9667            firm_type: default_firm_type(),
9668            billing_model: default_billing_model(),
9669            avg_hourly_rate: default_hourly_rate(),
9670            trust_accounting: TrustAccountingConfig::default(),
9671            anomaly_rates: ProfessionalServicesAnomalyRates::default(),
9672        }
9673    }
9674}
9675
9676/// Trust accounting configuration for law firms.
9677#[derive(Debug, Clone, Serialize, Deserialize)]
9678pub struct TrustAccountingConfig {
9679    /// Enable trust accounting.
9680    #[serde(default)]
9681    pub enabled: bool,
9682
9683    /// Require three-way reconciliation.
9684    #[serde(default = "default_true")]
9685    pub require_three_way_reconciliation: bool,
9686}
9687
9688impl Default for TrustAccountingConfig {
9689    fn default() -> Self {
9690        Self {
9691            enabled: false,
9692            require_three_way_reconciliation: true,
9693        }
9694    }
9695}
9696
9697/// Professional services anomaly injection rates.
9698#[derive(Debug, Clone, Serialize, Deserialize)]
9699pub struct ProfessionalServicesAnomalyRates {
9700    /// Time billing fraud rate.
9701    #[serde(default = "default_time_fraud_rate")]
9702    pub time_billing_fraud: f64,
9703
9704    /// Expense report fraud rate.
9705    #[serde(default = "default_expense_fraud_rate")]
9706    pub expense_fraud: f64,
9707
9708    /// Trust misappropriation rate.
9709    #[serde(default = "default_trust_misappropriation_rate")]
9710    pub trust_misappropriation: f64,
9711}
9712
9713fn default_time_fraud_rate() -> f64 {
9714    0.02
9715}
9716
9717fn default_expense_fraud_rate() -> f64 {
9718    0.015
9719}
9720
9721fn default_trust_misappropriation_rate() -> f64 {
9722    0.003
9723}
9724
9725impl Default for ProfessionalServicesAnomalyRates {
9726    fn default() -> Self {
9727        Self {
9728            time_billing_fraud: default_time_fraud_rate(),
9729            expense_fraud: default_expense_fraud_rate(),
9730            trust_misappropriation: default_trust_misappropriation_rate(),
9731        }
9732    }
9733}
9734
9735/// Fingerprint privacy configuration for extraction and synthesis.
9736///
9737/// Controls the privacy parameters used when extracting fingerprints
9738/// from sensitive data. Supports predefined levels or custom (epsilon, delta) tuples.
9739///
9740/// ```yaml
9741/// fingerprint_privacy:
9742///   level: custom
9743///   epsilon: 0.5
9744///   delta: 1.0e-5
9745///   k_anonymity: 10
9746///   composition_method: renyi_dp
9747/// ```
9748#[derive(Debug, Clone, Serialize, Deserialize)]
9749pub struct FingerprintPrivacyConfig {
9750    /// Privacy level preset. Use "custom" for user-specified epsilon/delta.
9751    #[serde(default)]
9752    pub level: String,
9753    /// Custom epsilon value (only used when level = "custom").
9754    #[serde(default = "default_epsilon")]
9755    pub epsilon: f64,
9756    /// Custom delta value for (epsilon, delta)-DP (only used with RDP/zCDP).
9757    #[serde(default = "default_delta")]
9758    pub delta: f64,
9759    /// K-anonymity threshold.
9760    #[serde(default = "default_k_anonymity")]
9761    pub k_anonymity: u32,
9762    /// Composition method: "naive", "advanced", "renyi_dp", "zcdp".
9763    #[serde(default)]
9764    pub composition_method: String,
9765}
9766
9767fn default_epsilon() -> f64 {
9768    1.0
9769}
9770
9771fn default_delta() -> f64 {
9772    1e-5
9773}
9774
9775fn default_k_anonymity() -> u32 {
9776    5
9777}
9778
9779impl Default for FingerprintPrivacyConfig {
9780    fn default() -> Self {
9781        Self {
9782            level: "standard".to_string(),
9783            epsilon: default_epsilon(),
9784            delta: default_delta(),
9785            k_anonymity: default_k_anonymity(),
9786            composition_method: "naive".to_string(),
9787        }
9788    }
9789}
9790
9791/// Quality gates configuration for pass/fail thresholds on generation runs.
9792///
9793/// ```yaml
9794/// quality_gates:
9795///   enabled: true
9796///   profile: strict  # strict, default, lenient, custom
9797///   fail_on_violation: true
9798///   custom_gates:
9799///     - name: benford_compliance
9800///       metric: benford_mad
9801///       threshold: 0.015
9802///       comparison: lte
9803/// ```
9804#[derive(Debug, Clone, Serialize, Deserialize)]
9805pub struct QualityGatesSchemaConfig {
9806    /// Enable quality gate evaluation.
9807    #[serde(default)]
9808    pub enabled: bool,
9809    /// Gate profile: "strict", "default", "lenient", or "custom".
9810    #[serde(default = "default_gate_profile_name")]
9811    pub profile: String,
9812    /// Whether to fail the generation on gate violations.
9813    #[serde(default)]
9814    pub fail_on_violation: bool,
9815    /// Custom gate definitions (used when profile = "custom").
9816    #[serde(default)]
9817    pub custom_gates: Vec<QualityGateEntry>,
9818}
9819
9820fn default_gate_profile_name() -> String {
9821    "default".to_string()
9822}
9823
9824impl Default for QualityGatesSchemaConfig {
9825    fn default() -> Self {
9826        Self {
9827            enabled: false,
9828            profile: default_gate_profile_name(),
9829            fail_on_violation: false,
9830            custom_gates: Vec::new(),
9831        }
9832    }
9833}
9834
9835/// A single quality gate entry in configuration.
9836#[derive(Debug, Clone, Serialize, Deserialize)]
9837pub struct QualityGateEntry {
9838    /// Gate name.
9839    pub name: String,
9840    /// Metric to check: benford_mad, balance_coherence, document_chain_integrity,
9841    /// correlation_preservation, temporal_consistency, privacy_mia_auc,
9842    /// completion_rate, duplicate_rate, referential_integrity, ic_match_rate.
9843    pub metric: String,
9844    /// Threshold value.
9845    pub threshold: f64,
9846    /// Upper threshold for "between" comparison.
9847    #[serde(default)]
9848    pub upper_threshold: Option<f64>,
9849    /// Comparison operator: "gte", "lte", "eq", "between".
9850    #[serde(default = "default_gate_comparison")]
9851    pub comparison: String,
9852}
9853
9854fn default_gate_comparison() -> String {
9855    "gte".to_string()
9856}
9857
9858/// Compliance configuration for regulatory requirements.
9859///
9860/// ```yaml
9861/// compliance:
9862///   content_marking:
9863///     enabled: true
9864///     format: embedded  # embedded, sidecar, both
9865///   article10_report: true
9866/// ```
9867#[derive(Debug, Clone, Default, Serialize, Deserialize)]
9868pub struct ComplianceSchemaConfig {
9869    /// Synthetic content marking configuration (EU AI Act Article 50).
9870    #[serde(default)]
9871    pub content_marking: ContentMarkingSchemaConfig,
9872    /// Generate Article 10 data governance report.
9873    #[serde(default)]
9874    pub article10_report: bool,
9875    /// Certificate configuration for proving DP guarantees.
9876    #[serde(default)]
9877    pub certificates: CertificateSchemaConfig,
9878}
9879
9880/// Configuration for synthetic data certificates.
9881#[derive(Debug, Clone, Default, Serialize, Deserialize)]
9882pub struct CertificateSchemaConfig {
9883    /// Whether certificate generation is enabled.
9884    #[serde(default)]
9885    pub enabled: bool,
9886    /// Environment variable name for the signing key.
9887    #[serde(default)]
9888    pub signing_key_env: Option<String>,
9889    /// Whether to include quality metrics in the certificate.
9890    #[serde(default)]
9891    pub include_quality_metrics: bool,
9892}
9893
9894/// Content marking configuration for synthetic data output.
9895#[derive(Debug, Clone, Serialize, Deserialize)]
9896pub struct ContentMarkingSchemaConfig {
9897    /// Whether content marking is enabled.
9898    #[serde(default = "default_true")]
9899    pub enabled: bool,
9900    /// Marking format: "embedded", "sidecar", or "both".
9901    #[serde(default = "default_marking_format")]
9902    pub format: String,
9903}
9904
9905fn default_marking_format() -> String {
9906    "embedded".to_string()
9907}
9908
9909impl Default for ContentMarkingSchemaConfig {
9910    fn default() -> Self {
9911        Self {
9912            enabled: true,
9913            format: default_marking_format(),
9914        }
9915    }
9916}
9917
9918/// Webhook notification configuration.
9919#[derive(Debug, Clone, Default, Serialize, Deserialize)]
9920pub struct WebhookSchemaConfig {
9921    /// Whether webhooks are enabled.
9922    #[serde(default)]
9923    pub enabled: bool,
9924    /// Webhook endpoint configurations.
9925    #[serde(default)]
9926    pub endpoints: Vec<WebhookEndpointConfig>,
9927}
9928
9929/// Configuration for a single webhook endpoint.
9930#[derive(Debug, Clone, Serialize, Deserialize)]
9931pub struct WebhookEndpointConfig {
9932    /// Target URL for the webhook.
9933    pub url: String,
9934    /// Event types this endpoint subscribes to.
9935    #[serde(default)]
9936    pub events: Vec<String>,
9937    /// Optional secret for HMAC-SHA256 signature.
9938    #[serde(default)]
9939    pub secret: Option<String>,
9940    /// Maximum retry attempts (default: 3).
9941    #[serde(default = "default_webhook_retries")]
9942    pub max_retries: u32,
9943    /// Timeout in seconds (default: 10).
9944    #[serde(default = "default_webhook_timeout")]
9945    pub timeout_secs: u64,
9946}
9947
9948fn default_webhook_retries() -> u32 {
9949    3
9950}
9951fn default_webhook_timeout() -> u64 {
9952    10
9953}
9954
9955// ===== Enterprise Process Chain Config Structs =====
9956
9957// ----- Source-to-Pay (S2C/S2P) -----
9958
9959/// Source-to-Pay configuration covering the entire sourcing lifecycle.
9960#[derive(Debug, Clone, Default, Serialize, Deserialize)]
9961pub struct SourceToPayConfig {
9962    /// Enable source-to-pay generation
9963    #[serde(default)]
9964    pub enabled: bool,
9965    /// Spend analysis configuration
9966    #[serde(default)]
9967    pub spend_analysis: SpendAnalysisConfig,
9968    /// Sourcing project configuration
9969    #[serde(default)]
9970    pub sourcing: SourcingConfig,
9971    /// Supplier qualification configuration
9972    #[serde(default)]
9973    pub qualification: QualificationConfig,
9974    /// RFx event configuration
9975    #[serde(default)]
9976    pub rfx: RfxConfig,
9977    /// Contract configuration
9978    #[serde(default)]
9979    pub contracts: ContractConfig,
9980    /// Catalog configuration
9981    #[serde(default)]
9982    pub catalog: CatalogConfig,
9983    /// Scorecard configuration
9984    #[serde(default)]
9985    pub scorecards: ScorecardConfig,
9986    /// P2P integration settings
9987    #[serde(default)]
9988    pub p2p_integration: P2PIntegrationConfig,
9989}
9990
9991/// Spend analysis configuration.
9992#[derive(Debug, Clone, Serialize, Deserialize)]
9993pub struct SpendAnalysisConfig {
9994    /// HHI threshold for triggering sourcing project
9995    #[serde(default = "default_hhi_threshold")]
9996    pub hhi_threshold: f64,
9997    /// Target spend coverage under contracts
9998    #[serde(default = "default_contract_coverage_target")]
9999    pub contract_coverage_target: f64,
10000}
10001
10002impl Default for SpendAnalysisConfig {
10003    fn default() -> Self {
10004        Self {
10005            hhi_threshold: default_hhi_threshold(),
10006            contract_coverage_target: default_contract_coverage_target(),
10007        }
10008    }
10009}
10010
10011fn default_hhi_threshold() -> f64 {
10012    2500.0
10013}
10014fn default_contract_coverage_target() -> f64 {
10015    0.80
10016}
10017
10018/// Sourcing project configuration.
10019#[derive(Debug, Clone, Serialize, Deserialize)]
10020pub struct SourcingConfig {
10021    /// Number of sourcing projects per year
10022    #[serde(default = "default_sourcing_projects_per_year")]
10023    pub projects_per_year: u32,
10024    /// Months before expiry to trigger renewal project
10025    #[serde(default = "default_renewal_horizon_months")]
10026    pub renewal_horizon_months: u32,
10027    /// Average project duration in months
10028    #[serde(default = "default_project_duration_months")]
10029    pub project_duration_months: u32,
10030}
10031
10032impl Default for SourcingConfig {
10033    fn default() -> Self {
10034        Self {
10035            projects_per_year: default_sourcing_projects_per_year(),
10036            renewal_horizon_months: default_renewal_horizon_months(),
10037            project_duration_months: default_project_duration_months(),
10038        }
10039    }
10040}
10041
10042fn default_sourcing_projects_per_year() -> u32 {
10043    10
10044}
10045fn default_renewal_horizon_months() -> u32 {
10046    3
10047}
10048fn default_project_duration_months() -> u32 {
10049    4
10050}
10051
10052/// Supplier qualification configuration.
10053#[derive(Debug, Clone, Serialize, Deserialize)]
10054pub struct QualificationConfig {
10055    /// Pass rate for qualification
10056    #[serde(default = "default_qualification_pass_rate")]
10057    pub pass_rate: f64,
10058    /// Qualification validity in days
10059    #[serde(default = "default_qualification_validity_days")]
10060    pub validity_days: u32,
10061    /// Financial stability weight
10062    #[serde(default = "default_financial_weight")]
10063    pub financial_weight: f64,
10064    /// Quality management weight
10065    #[serde(default = "default_quality_weight")]
10066    pub quality_weight: f64,
10067    /// Delivery performance weight
10068    #[serde(default = "default_delivery_weight")]
10069    pub delivery_weight: f64,
10070    /// Compliance weight
10071    #[serde(default = "default_compliance_weight")]
10072    pub compliance_weight: f64,
10073}
10074
10075impl Default for QualificationConfig {
10076    fn default() -> Self {
10077        Self {
10078            pass_rate: default_qualification_pass_rate(),
10079            validity_days: default_qualification_validity_days(),
10080            financial_weight: default_financial_weight(),
10081            quality_weight: default_quality_weight(),
10082            delivery_weight: default_delivery_weight(),
10083            compliance_weight: default_compliance_weight(),
10084        }
10085    }
10086}
10087
10088fn default_qualification_pass_rate() -> f64 {
10089    0.75
10090}
10091fn default_qualification_validity_days() -> u32 {
10092    365
10093}
10094fn default_financial_weight() -> f64 {
10095    0.25
10096}
10097fn default_quality_weight() -> f64 {
10098    0.30
10099}
10100fn default_delivery_weight() -> f64 {
10101    0.25
10102}
10103fn default_compliance_weight() -> f64 {
10104    0.20
10105}
10106
10107/// RFx event configuration.
10108#[derive(Debug, Clone, Serialize, Deserialize)]
10109pub struct RfxConfig {
10110    /// Spend threshold above which RFI is required before RFP
10111    #[serde(default = "default_rfi_threshold")]
10112    pub rfi_threshold: f64,
10113    /// Minimum vendors invited per RFx
10114    #[serde(default = "default_min_invited_vendors")]
10115    pub min_invited_vendors: u32,
10116    /// Maximum vendors invited per RFx
10117    #[serde(default = "default_max_invited_vendors")]
10118    pub max_invited_vendors: u32,
10119    /// Response rate (% of invited vendors that submit bids)
10120    #[serde(default = "default_response_rate")]
10121    pub response_rate: f64,
10122    /// Default price weight in evaluation
10123    #[serde(default = "default_price_weight")]
10124    pub default_price_weight: f64,
10125    /// Default quality weight in evaluation
10126    #[serde(default = "default_rfx_quality_weight")]
10127    pub default_quality_weight: f64,
10128    /// Default delivery weight in evaluation
10129    #[serde(default = "default_rfx_delivery_weight")]
10130    pub default_delivery_weight: f64,
10131}
10132
10133impl Default for RfxConfig {
10134    fn default() -> Self {
10135        Self {
10136            rfi_threshold: default_rfi_threshold(),
10137            min_invited_vendors: default_min_invited_vendors(),
10138            max_invited_vendors: default_max_invited_vendors(),
10139            response_rate: default_response_rate(),
10140            default_price_weight: default_price_weight(),
10141            default_quality_weight: default_rfx_quality_weight(),
10142            default_delivery_weight: default_rfx_delivery_weight(),
10143        }
10144    }
10145}
10146
10147fn default_rfi_threshold() -> f64 {
10148    100_000.0
10149}
10150fn default_min_invited_vendors() -> u32 {
10151    3
10152}
10153fn default_max_invited_vendors() -> u32 {
10154    8
10155}
10156fn default_response_rate() -> f64 {
10157    0.70
10158}
10159fn default_price_weight() -> f64 {
10160    0.40
10161}
10162fn default_rfx_quality_weight() -> f64 {
10163    0.35
10164}
10165fn default_rfx_delivery_weight() -> f64 {
10166    0.25
10167}
10168
10169/// Contract configuration.
10170#[derive(Debug, Clone, Serialize, Deserialize)]
10171pub struct ContractConfig {
10172    /// Minimum contract duration in months
10173    #[serde(default = "default_min_contract_months")]
10174    pub min_duration_months: u32,
10175    /// Maximum contract duration in months
10176    #[serde(default = "default_max_contract_months")]
10177    pub max_duration_months: u32,
10178    /// Auto-renewal rate
10179    #[serde(default = "default_auto_renewal_rate")]
10180    pub auto_renewal_rate: f64,
10181    /// Amendment rate (% of contracts with at least one amendment)
10182    #[serde(default = "default_amendment_rate")]
10183    pub amendment_rate: f64,
10184    /// Distribution of contract types
10185    #[serde(default)]
10186    pub type_distribution: ContractTypeDistribution,
10187}
10188
10189impl Default for ContractConfig {
10190    fn default() -> Self {
10191        Self {
10192            min_duration_months: default_min_contract_months(),
10193            max_duration_months: default_max_contract_months(),
10194            auto_renewal_rate: default_auto_renewal_rate(),
10195            amendment_rate: default_amendment_rate(),
10196            type_distribution: ContractTypeDistribution::default(),
10197        }
10198    }
10199}
10200
10201fn default_min_contract_months() -> u32 {
10202    12
10203}
10204fn default_max_contract_months() -> u32 {
10205    36
10206}
10207fn default_auto_renewal_rate() -> f64 {
10208    0.40
10209}
10210fn default_amendment_rate() -> f64 {
10211    0.20
10212}
10213
10214/// Distribution of contract types.
10215#[derive(Debug, Clone, Serialize, Deserialize)]
10216pub struct ContractTypeDistribution {
10217    /// Fixed price percentage
10218    #[serde(default = "default_fixed_price_pct")]
10219    pub fixed_price: f64,
10220    /// Blanket/framework percentage
10221    #[serde(default = "default_blanket_pct")]
10222    pub blanket: f64,
10223    /// Time and materials percentage
10224    #[serde(default = "default_time_materials_pct")]
10225    pub time_and_materials: f64,
10226    /// Service agreement percentage
10227    #[serde(default = "default_service_agreement_pct")]
10228    pub service_agreement: f64,
10229}
10230
10231impl Default for ContractTypeDistribution {
10232    fn default() -> Self {
10233        Self {
10234            fixed_price: default_fixed_price_pct(),
10235            blanket: default_blanket_pct(),
10236            time_and_materials: default_time_materials_pct(),
10237            service_agreement: default_service_agreement_pct(),
10238        }
10239    }
10240}
10241
10242fn default_fixed_price_pct() -> f64 {
10243    0.40
10244}
10245fn default_blanket_pct() -> f64 {
10246    0.30
10247}
10248fn default_time_materials_pct() -> f64 {
10249    0.15
10250}
10251fn default_service_agreement_pct() -> f64 {
10252    0.15
10253}
10254
10255/// Catalog configuration.
10256#[derive(Debug, Clone, Serialize, Deserialize)]
10257pub struct CatalogConfig {
10258    /// Percentage of catalog items marked as preferred
10259    #[serde(default = "default_preferred_vendor_flag_rate")]
10260    pub preferred_vendor_flag_rate: f64,
10261    /// Rate of materials with multiple sources in catalog
10262    #[serde(default = "default_multi_source_rate")]
10263    pub multi_source_rate: f64,
10264}
10265
10266impl Default for CatalogConfig {
10267    fn default() -> Self {
10268        Self {
10269            preferred_vendor_flag_rate: default_preferred_vendor_flag_rate(),
10270            multi_source_rate: default_multi_source_rate(),
10271        }
10272    }
10273}
10274
10275fn default_preferred_vendor_flag_rate() -> f64 {
10276    0.70
10277}
10278fn default_multi_source_rate() -> f64 {
10279    0.25
10280}
10281
10282/// Scorecard configuration.
10283#[derive(Debug, Clone, Serialize, Deserialize)]
10284pub struct ScorecardConfig {
10285    /// Scorecard review frequency (quarterly, monthly)
10286    #[serde(default = "default_scorecard_frequency")]
10287    pub frequency: String,
10288    /// On-time delivery weight in overall score
10289    #[serde(default = "default_otd_weight")]
10290    pub on_time_delivery_weight: f64,
10291    /// Quality weight in overall score
10292    #[serde(default = "default_quality_score_weight")]
10293    pub quality_weight: f64,
10294    /// Price competitiveness weight
10295    #[serde(default = "default_price_score_weight")]
10296    pub price_weight: f64,
10297    /// Responsiveness weight
10298    #[serde(default = "default_responsiveness_weight")]
10299    pub responsiveness_weight: f64,
10300    /// Grade A threshold (score >= this)
10301    #[serde(default = "default_grade_a_threshold")]
10302    pub grade_a_threshold: f64,
10303    /// Grade B threshold
10304    #[serde(default = "default_grade_b_threshold")]
10305    pub grade_b_threshold: f64,
10306    /// Grade C threshold
10307    #[serde(default = "default_grade_c_threshold")]
10308    pub grade_c_threshold: f64,
10309}
10310
10311impl Default for ScorecardConfig {
10312    fn default() -> Self {
10313        Self {
10314            frequency: default_scorecard_frequency(),
10315            on_time_delivery_weight: default_otd_weight(),
10316            quality_weight: default_quality_score_weight(),
10317            price_weight: default_price_score_weight(),
10318            responsiveness_weight: default_responsiveness_weight(),
10319            grade_a_threshold: default_grade_a_threshold(),
10320            grade_b_threshold: default_grade_b_threshold(),
10321            grade_c_threshold: default_grade_c_threshold(),
10322        }
10323    }
10324}
10325
10326fn default_scorecard_frequency() -> String {
10327    "quarterly".to_string()
10328}
10329fn default_otd_weight() -> f64 {
10330    0.30
10331}
10332fn default_quality_score_weight() -> f64 {
10333    0.30
10334}
10335fn default_price_score_weight() -> f64 {
10336    0.25
10337}
10338fn default_responsiveness_weight() -> f64 {
10339    0.15
10340}
10341fn default_grade_a_threshold() -> f64 {
10342    90.0
10343}
10344fn default_grade_b_threshold() -> f64 {
10345    75.0
10346}
10347fn default_grade_c_threshold() -> f64 {
10348    60.0
10349}
10350
10351/// P2P integration settings for contract enforcement.
10352#[derive(Debug, Clone, Serialize, Deserialize)]
10353pub struct P2PIntegrationConfig {
10354    /// Rate of off-contract (maverick) purchases
10355    #[serde(default = "default_off_contract_rate")]
10356    pub off_contract_rate: f64,
10357    /// Price tolerance for contract price validation
10358    #[serde(default = "default_price_tolerance")]
10359    pub price_tolerance: f64,
10360    /// Whether to enforce catalog ordering
10361    #[serde(default)]
10362    pub catalog_enforcement: bool,
10363}
10364
10365impl Default for P2PIntegrationConfig {
10366    fn default() -> Self {
10367        Self {
10368            off_contract_rate: default_off_contract_rate(),
10369            price_tolerance: default_price_tolerance(),
10370            catalog_enforcement: false,
10371        }
10372    }
10373}
10374
10375fn default_off_contract_rate() -> f64 {
10376    0.15
10377}
10378fn default_price_tolerance() -> f64 {
10379    0.02
10380}
10381
10382// ----- Financial Reporting -----
10383
10384/// Financial reporting configuration.
10385#[derive(Debug, Clone, Serialize, Deserialize)]
10386pub struct FinancialReportingConfig {
10387    /// Enable financial reporting generation
10388    #[serde(default)]
10389    pub enabled: bool,
10390    /// Generate balance sheet
10391    #[serde(default = "default_true")]
10392    pub generate_balance_sheet: bool,
10393    /// Generate income statement
10394    #[serde(default = "default_true")]
10395    pub generate_income_statement: bool,
10396    /// Generate cash flow statement
10397    #[serde(default = "default_true")]
10398    pub generate_cash_flow: bool,
10399    /// Generate changes in equity statement
10400    #[serde(default = "default_true")]
10401    pub generate_changes_in_equity: bool,
10402    /// Number of comparative periods
10403    #[serde(default = "default_comparative_periods")]
10404    pub comparative_periods: u32,
10405    /// Management KPIs configuration
10406    #[serde(default)]
10407    pub management_kpis: ManagementKpisConfig,
10408    /// Budget configuration
10409    #[serde(default)]
10410    pub budgets: BudgetConfig,
10411}
10412
10413impl Default for FinancialReportingConfig {
10414    fn default() -> Self {
10415        Self {
10416            enabled: false,
10417            generate_balance_sheet: true,
10418            generate_income_statement: true,
10419            generate_cash_flow: true,
10420            generate_changes_in_equity: true,
10421            comparative_periods: default_comparative_periods(),
10422            management_kpis: ManagementKpisConfig::default(),
10423            budgets: BudgetConfig::default(),
10424        }
10425    }
10426}
10427
10428fn default_comparative_periods() -> u32 {
10429    1
10430}
10431
10432/// Management KPIs configuration.
10433#[derive(Debug, Clone, Default, Serialize, Deserialize)]
10434pub struct ManagementKpisConfig {
10435    /// Enable KPI generation
10436    #[serde(default)]
10437    pub enabled: bool,
10438    /// KPI calculation frequency (monthly, quarterly)
10439    #[serde(default = "default_kpi_frequency")]
10440    pub frequency: String,
10441}
10442
10443fn default_kpi_frequency() -> String {
10444    "monthly".to_string()
10445}
10446
10447/// Budget configuration.
10448#[derive(Debug, Clone, Serialize, Deserialize)]
10449pub struct BudgetConfig {
10450    /// Enable budget generation
10451    #[serde(default)]
10452    pub enabled: bool,
10453    /// Expected revenue growth rate for budgeting
10454    #[serde(default = "default_revenue_growth_rate")]
10455    pub revenue_growth_rate: f64,
10456    /// Expected expense inflation rate
10457    #[serde(default = "default_expense_inflation_rate")]
10458    pub expense_inflation_rate: f64,
10459    /// Random noise to add to budget vs actual
10460    #[serde(default = "default_variance_noise")]
10461    pub variance_noise: f64,
10462}
10463
10464impl Default for BudgetConfig {
10465    fn default() -> Self {
10466        Self {
10467            enabled: false,
10468            revenue_growth_rate: default_revenue_growth_rate(),
10469            expense_inflation_rate: default_expense_inflation_rate(),
10470            variance_noise: default_variance_noise(),
10471        }
10472    }
10473}
10474
10475fn default_revenue_growth_rate() -> f64 {
10476    0.05
10477}
10478fn default_expense_inflation_rate() -> f64 {
10479    0.03
10480}
10481fn default_variance_noise() -> f64 {
10482    0.10
10483}
10484
10485// ----- HR Configuration -----
10486
10487/// HR (Hire-to-Retire) process configuration.
10488#[derive(Debug, Clone, Default, Serialize, Deserialize)]
10489pub struct HrConfig {
10490    /// Enable HR generation
10491    #[serde(default)]
10492    pub enabled: bool,
10493    /// Payroll configuration
10494    #[serde(default)]
10495    pub payroll: PayrollConfig,
10496    /// Time and attendance configuration
10497    #[serde(default)]
10498    pub time_attendance: TimeAttendanceConfig,
10499    /// Expense management configuration
10500    #[serde(default)]
10501    pub expenses: ExpenseConfig,
10502}
10503
10504/// Payroll configuration.
10505#[derive(Debug, Clone, Serialize, Deserialize)]
10506pub struct PayrollConfig {
10507    /// Enable payroll generation
10508    #[serde(default = "default_true")]
10509    pub enabled: bool,
10510    /// Pay frequency (monthly, biweekly, weekly)
10511    #[serde(default = "default_pay_frequency")]
10512    pub pay_frequency: String,
10513    /// Salary ranges by job level
10514    #[serde(default)]
10515    pub salary_ranges: PayrollSalaryRanges,
10516    /// Effective tax rates
10517    #[serde(default)]
10518    pub tax_rates: PayrollTaxRates,
10519    /// Benefits enrollment rate
10520    #[serde(default = "default_benefits_enrollment_rate")]
10521    pub benefits_enrollment_rate: f64,
10522    /// Retirement plan participation rate
10523    #[serde(default = "default_retirement_participation_rate")]
10524    pub retirement_participation_rate: f64,
10525}
10526
10527impl Default for PayrollConfig {
10528    fn default() -> Self {
10529        Self {
10530            enabled: true,
10531            pay_frequency: default_pay_frequency(),
10532            salary_ranges: PayrollSalaryRanges::default(),
10533            tax_rates: PayrollTaxRates::default(),
10534            benefits_enrollment_rate: default_benefits_enrollment_rate(),
10535            retirement_participation_rate: default_retirement_participation_rate(),
10536        }
10537    }
10538}
10539
10540fn default_pay_frequency() -> String {
10541    "monthly".to_string()
10542}
10543fn default_benefits_enrollment_rate() -> f64 {
10544    0.60
10545}
10546fn default_retirement_participation_rate() -> f64 {
10547    0.45
10548}
10549
10550/// Salary ranges by job level.
10551#[derive(Debug, Clone, Serialize, Deserialize)]
10552pub struct PayrollSalaryRanges {
10553    /// Staff level min/max
10554    #[serde(default = "default_staff_min")]
10555    pub staff_min: f64,
10556    #[serde(default = "default_staff_max")]
10557    pub staff_max: f64,
10558    /// Manager level min/max
10559    #[serde(default = "default_manager_min")]
10560    pub manager_min: f64,
10561    #[serde(default = "default_manager_max")]
10562    pub manager_max: f64,
10563    /// Director level min/max
10564    #[serde(default = "default_director_min")]
10565    pub director_min: f64,
10566    #[serde(default = "default_director_max")]
10567    pub director_max: f64,
10568    /// Executive level min/max
10569    #[serde(default = "default_executive_min")]
10570    pub executive_min: f64,
10571    #[serde(default = "default_executive_max")]
10572    pub executive_max: f64,
10573}
10574
10575impl Default for PayrollSalaryRanges {
10576    fn default() -> Self {
10577        Self {
10578            staff_min: default_staff_min(),
10579            staff_max: default_staff_max(),
10580            manager_min: default_manager_min(),
10581            manager_max: default_manager_max(),
10582            director_min: default_director_min(),
10583            director_max: default_director_max(),
10584            executive_min: default_executive_min(),
10585            executive_max: default_executive_max(),
10586        }
10587    }
10588}
10589
10590fn default_staff_min() -> f64 {
10591    50_000.0
10592}
10593fn default_staff_max() -> f64 {
10594    70_000.0
10595}
10596fn default_manager_min() -> f64 {
10597    80_000.0
10598}
10599fn default_manager_max() -> f64 {
10600    120_000.0
10601}
10602fn default_director_min() -> f64 {
10603    120_000.0
10604}
10605fn default_director_max() -> f64 {
10606    180_000.0
10607}
10608fn default_executive_min() -> f64 {
10609    180_000.0
10610}
10611fn default_executive_max() -> f64 {
10612    350_000.0
10613}
10614
10615/// Effective tax rates for payroll.
10616#[derive(Debug, Clone, Serialize, Deserialize)]
10617pub struct PayrollTaxRates {
10618    /// Federal effective tax rate
10619    #[serde(default = "default_federal_rate")]
10620    pub federal_effective: f64,
10621    /// State effective tax rate
10622    #[serde(default = "default_state_rate")]
10623    pub state_effective: f64,
10624    /// FICA/social security rate
10625    #[serde(default = "default_fica_rate")]
10626    pub fica: f64,
10627}
10628
10629impl Default for PayrollTaxRates {
10630    fn default() -> Self {
10631        Self {
10632            federal_effective: default_federal_rate(),
10633            state_effective: default_state_rate(),
10634            fica: default_fica_rate(),
10635        }
10636    }
10637}
10638
10639fn default_federal_rate() -> f64 {
10640    0.22
10641}
10642fn default_state_rate() -> f64 {
10643    0.05
10644}
10645fn default_fica_rate() -> f64 {
10646    0.0765
10647}
10648
10649/// Time and attendance configuration.
10650#[derive(Debug, Clone, Serialize, Deserialize)]
10651pub struct TimeAttendanceConfig {
10652    /// Enable time tracking
10653    #[serde(default = "default_true")]
10654    pub enabled: bool,
10655    /// Overtime rate (% of employees with overtime in a period)
10656    #[serde(default = "default_overtime_rate")]
10657    pub overtime_rate: f64,
10658}
10659
10660impl Default for TimeAttendanceConfig {
10661    fn default() -> Self {
10662        Self {
10663            enabled: true,
10664            overtime_rate: default_overtime_rate(),
10665        }
10666    }
10667}
10668
10669fn default_overtime_rate() -> f64 {
10670    0.10
10671}
10672
10673/// Expense management configuration.
10674#[derive(Debug, Clone, Serialize, Deserialize)]
10675pub struct ExpenseConfig {
10676    /// Enable expense report generation
10677    #[serde(default = "default_true")]
10678    pub enabled: bool,
10679    /// Rate of employees submitting expenses per month
10680    #[serde(default = "default_expense_submission_rate")]
10681    pub submission_rate: f64,
10682    /// Rate of policy violations
10683    #[serde(default = "default_policy_violation_rate")]
10684    pub policy_violation_rate: f64,
10685}
10686
10687impl Default for ExpenseConfig {
10688    fn default() -> Self {
10689        Self {
10690            enabled: true,
10691            submission_rate: default_expense_submission_rate(),
10692            policy_violation_rate: default_policy_violation_rate(),
10693        }
10694    }
10695}
10696
10697fn default_expense_submission_rate() -> f64 {
10698    0.30
10699}
10700fn default_policy_violation_rate() -> f64 {
10701    0.08
10702}
10703
10704// ----- Manufacturing Configuration -----
10705
10706/// Manufacturing process configuration (production orders, WIP, routing).
10707#[derive(Debug, Clone, Default, Serialize, Deserialize)]
10708pub struct ManufacturingProcessConfig {
10709    /// Enable manufacturing generation
10710    #[serde(default)]
10711    pub enabled: bool,
10712    /// Production order configuration
10713    #[serde(default)]
10714    pub production_orders: ProductionOrderConfig,
10715    /// Costing configuration
10716    #[serde(default)]
10717    pub costing: ManufacturingCostingConfig,
10718    /// Routing configuration
10719    #[serde(default)]
10720    pub routing: RoutingConfig,
10721}
10722
10723/// Production order configuration.
10724#[derive(Debug, Clone, Serialize, Deserialize)]
10725pub struct ProductionOrderConfig {
10726    /// Orders per month
10727    #[serde(default = "default_prod_orders_per_month")]
10728    pub orders_per_month: u32,
10729    /// Average batch size
10730    #[serde(default = "default_prod_avg_batch_size")]
10731    pub avg_batch_size: u32,
10732    /// Yield rate
10733    #[serde(default = "default_prod_yield_rate")]
10734    pub yield_rate: f64,
10735    /// Make-to-order rate (vs make-to-stock)
10736    #[serde(default = "default_prod_make_to_order_rate")]
10737    pub make_to_order_rate: f64,
10738    /// Rework rate
10739    #[serde(default = "default_prod_rework_rate")]
10740    pub rework_rate: f64,
10741}
10742
10743impl Default for ProductionOrderConfig {
10744    fn default() -> Self {
10745        Self {
10746            orders_per_month: default_prod_orders_per_month(),
10747            avg_batch_size: default_prod_avg_batch_size(),
10748            yield_rate: default_prod_yield_rate(),
10749            make_to_order_rate: default_prod_make_to_order_rate(),
10750            rework_rate: default_prod_rework_rate(),
10751        }
10752    }
10753}
10754
10755fn default_prod_orders_per_month() -> u32 {
10756    50
10757}
10758fn default_prod_avg_batch_size() -> u32 {
10759    100
10760}
10761fn default_prod_yield_rate() -> f64 {
10762    0.97
10763}
10764fn default_prod_make_to_order_rate() -> f64 {
10765    0.20
10766}
10767fn default_prod_rework_rate() -> f64 {
10768    0.03
10769}
10770
10771/// Manufacturing costing configuration.
10772#[derive(Debug, Clone, Serialize, Deserialize)]
10773pub struct ManufacturingCostingConfig {
10774    /// Labor rate per hour
10775    #[serde(default = "default_labor_rate")]
10776    pub labor_rate_per_hour: f64,
10777    /// Overhead application rate (multiplier on direct labor)
10778    #[serde(default = "default_overhead_rate")]
10779    pub overhead_rate: f64,
10780    /// Standard cost update frequency
10781    #[serde(default = "default_cost_update_frequency")]
10782    pub standard_cost_update_frequency: String,
10783}
10784
10785impl Default for ManufacturingCostingConfig {
10786    fn default() -> Self {
10787        Self {
10788            labor_rate_per_hour: default_labor_rate(),
10789            overhead_rate: default_overhead_rate(),
10790            standard_cost_update_frequency: default_cost_update_frequency(),
10791        }
10792    }
10793}
10794
10795fn default_labor_rate() -> f64 {
10796    35.0
10797}
10798fn default_overhead_rate() -> f64 {
10799    1.50
10800}
10801fn default_cost_update_frequency() -> String {
10802    "quarterly".to_string()
10803}
10804
10805/// Routing configuration for production operations.
10806#[derive(Debug, Clone, Serialize, Deserialize)]
10807pub struct RoutingConfig {
10808    /// Average number of operations per routing
10809    #[serde(default = "default_avg_operations")]
10810    pub avg_operations: u32,
10811    /// Average setup time in hours
10812    #[serde(default = "default_setup_time")]
10813    pub setup_time_hours: f64,
10814    /// Run time variation coefficient
10815    #[serde(default = "default_run_time_variation")]
10816    pub run_time_variation: f64,
10817}
10818
10819impl Default for RoutingConfig {
10820    fn default() -> Self {
10821        Self {
10822            avg_operations: default_avg_operations(),
10823            setup_time_hours: default_setup_time(),
10824            run_time_variation: default_run_time_variation(),
10825        }
10826    }
10827}
10828
10829fn default_avg_operations() -> u32 {
10830    4
10831}
10832fn default_setup_time() -> f64 {
10833    1.5
10834}
10835fn default_run_time_variation() -> f64 {
10836    0.15
10837}
10838
10839// ----- Sales Quote Configuration -----
10840
10841/// Sales quote (quote-to-order) pipeline configuration.
10842#[derive(Debug, Clone, Serialize, Deserialize)]
10843pub struct SalesQuoteConfig {
10844    /// Enable sales quote generation
10845    #[serde(default)]
10846    pub enabled: bool,
10847    /// Quotes per month
10848    #[serde(default = "default_quotes_per_month")]
10849    pub quotes_per_month: u32,
10850    /// Win rate (fraction of quotes that convert to orders)
10851    #[serde(default = "default_quote_win_rate")]
10852    pub win_rate: f64,
10853    /// Average quote validity in days
10854    #[serde(default = "default_quote_validity_days")]
10855    pub validity_days: u32,
10856}
10857
10858impl Default for SalesQuoteConfig {
10859    fn default() -> Self {
10860        Self {
10861            enabled: false,
10862            quotes_per_month: default_quotes_per_month(),
10863            win_rate: default_quote_win_rate(),
10864            validity_days: default_quote_validity_days(),
10865        }
10866    }
10867}
10868
10869fn default_quotes_per_month() -> u32 {
10870    30
10871}
10872fn default_quote_win_rate() -> f64 {
10873    0.35
10874}
10875fn default_quote_validity_days() -> u32 {
10876    30
10877}
10878
10879// =============================================================================
10880// Tax Accounting Configuration
10881// =============================================================================
10882
10883/// Tax accounting configuration.
10884///
10885/// Controls generation of tax-related data including VAT/GST, sales tax,
10886/// withholding tax, tax provisions, and payroll tax across multiple jurisdictions.
10887#[derive(Debug, Clone, Serialize, Deserialize)]
10888pub struct TaxConfig {
10889    /// Whether tax generation is enabled.
10890    #[serde(default)]
10891    pub enabled: bool,
10892    /// Tax jurisdiction configuration.
10893    #[serde(default)]
10894    pub jurisdictions: TaxJurisdictionConfig,
10895    /// VAT/GST configuration.
10896    #[serde(default)]
10897    pub vat_gst: VatGstConfig,
10898    /// Sales tax configuration.
10899    #[serde(default)]
10900    pub sales_tax: SalesTaxConfig,
10901    /// Withholding tax configuration.
10902    #[serde(default)]
10903    pub withholding: WithholdingTaxSchemaConfig,
10904    /// Tax provision configuration.
10905    #[serde(default)]
10906    pub provisions: TaxProvisionSchemaConfig,
10907    /// Payroll tax configuration.
10908    #[serde(default)]
10909    pub payroll_tax: PayrollTaxSchemaConfig,
10910    /// Anomaly injection rate for tax data (0.0 to 1.0).
10911    #[serde(default = "default_tax_anomaly_rate")]
10912    pub anomaly_rate: f64,
10913}
10914
10915fn default_tax_anomaly_rate() -> f64 {
10916    0.03
10917}
10918
10919impl Default for TaxConfig {
10920    fn default() -> Self {
10921        Self {
10922            enabled: false,
10923            jurisdictions: TaxJurisdictionConfig::default(),
10924            vat_gst: VatGstConfig::default(),
10925            sales_tax: SalesTaxConfig::default(),
10926            withholding: WithholdingTaxSchemaConfig::default(),
10927            provisions: TaxProvisionSchemaConfig::default(),
10928            payroll_tax: PayrollTaxSchemaConfig::default(),
10929            anomaly_rate: default_tax_anomaly_rate(),
10930        }
10931    }
10932}
10933
10934/// Tax jurisdiction configuration.
10935///
10936/// Specifies which countries and subnational jurisdictions to include
10937/// when generating tax data.
10938#[derive(Debug, Clone, Default, Serialize, Deserialize)]
10939pub struct TaxJurisdictionConfig {
10940    /// List of country codes to include (e.g., ["US", "DE", "GB"]).
10941    #[serde(default)]
10942    pub countries: Vec<String>,
10943    /// Whether to include subnational jurisdictions (e.g., US states, Canadian provinces).
10944    #[serde(default)]
10945    pub include_subnational: bool,
10946}
10947
10948/// VAT/GST configuration.
10949///
10950/// Controls generation of Value Added Tax / Goods and Services Tax data,
10951/// including standard and reduced rates, exempt categories, and reverse charge.
10952#[derive(Debug, Clone, Serialize, Deserialize)]
10953pub struct VatGstConfig {
10954    /// Whether VAT/GST generation is enabled.
10955    #[serde(default)]
10956    pub enabled: bool,
10957    /// Standard VAT/GST rates by country code (e.g., {"DE": 0.19, "GB": 0.20}).
10958    #[serde(default)]
10959    pub standard_rates: std::collections::HashMap<String, f64>,
10960    /// Reduced VAT/GST rates by country code (e.g., {"DE": 0.07, "GB": 0.05}).
10961    #[serde(default)]
10962    pub reduced_rates: std::collections::HashMap<String, f64>,
10963    /// Categories exempt from VAT/GST (e.g., ["financial_services", "healthcare"]).
10964    #[serde(default)]
10965    pub exempt_categories: Vec<String>,
10966    /// Whether to apply reverse charge mechanism for cross-border B2B transactions.
10967    #[serde(default = "default_true")]
10968    pub reverse_charge: bool,
10969}
10970
10971impl Default for VatGstConfig {
10972    fn default() -> Self {
10973        Self {
10974            enabled: false,
10975            standard_rates: std::collections::HashMap::new(),
10976            reduced_rates: std::collections::HashMap::new(),
10977            exempt_categories: Vec::new(),
10978            reverse_charge: true,
10979        }
10980    }
10981}
10982
10983/// Sales tax configuration.
10984///
10985/// Controls generation of US-style sales tax data including nexus determination.
10986#[derive(Debug, Clone, Default, Serialize, Deserialize)]
10987pub struct SalesTaxConfig {
10988    /// Whether sales tax generation is enabled.
10989    #[serde(default)]
10990    pub enabled: bool,
10991    /// US states where the company has nexus (e.g., ["CA", "NY", "TX"]).
10992    #[serde(default)]
10993    pub nexus_states: Vec<String>,
10994}
10995
10996/// Withholding tax configuration.
10997///
10998/// Controls generation of withholding tax data for cross-border payments,
10999/// including treaty network and rate overrides.
11000#[derive(Debug, Clone, Serialize, Deserialize)]
11001pub struct WithholdingTaxSchemaConfig {
11002    /// Whether withholding tax generation is enabled.
11003    #[serde(default)]
11004    pub enabled: bool,
11005    /// Whether to simulate a treaty network with reduced rates.
11006    #[serde(default = "default_true")]
11007    pub treaty_network: bool,
11008    /// Default withholding tax rate for non-treaty countries (0.0 to 1.0).
11009    #[serde(default = "default_withholding_rate")]
11010    pub default_rate: f64,
11011    /// Reduced withholding tax rate for treaty countries (0.0 to 1.0).
11012    #[serde(default = "default_treaty_reduced_rate")]
11013    pub treaty_reduced_rate: f64,
11014}
11015
11016fn default_withholding_rate() -> f64 {
11017    0.30
11018}
11019
11020fn default_treaty_reduced_rate() -> f64 {
11021    0.15
11022}
11023
11024impl Default for WithholdingTaxSchemaConfig {
11025    fn default() -> Self {
11026        Self {
11027            enabled: false,
11028            treaty_network: true,
11029            default_rate: default_withholding_rate(),
11030            treaty_reduced_rate: default_treaty_reduced_rate(),
11031        }
11032    }
11033}
11034
11035/// Tax provision configuration.
11036///
11037/// Controls generation of tax provision data including statutory rates
11038/// and uncertain tax positions (ASC 740 / IAS 12).
11039#[derive(Debug, Clone, Serialize, Deserialize)]
11040pub struct TaxProvisionSchemaConfig {
11041    /// Whether tax provision generation is enabled.
11042    /// Defaults to true when tax is enabled, as provisions are typically required.
11043    #[serde(default = "default_true")]
11044    pub enabled: bool,
11045    /// Statutory corporate tax rate (0.0 to 1.0).
11046    #[serde(default = "default_statutory_rate")]
11047    pub statutory_rate: f64,
11048    /// Whether to generate uncertain tax positions (FIN 48 / IFRIC 23).
11049    #[serde(default = "default_true")]
11050    pub uncertain_positions: bool,
11051}
11052
11053fn default_statutory_rate() -> f64 {
11054    0.21
11055}
11056
11057impl Default for TaxProvisionSchemaConfig {
11058    fn default() -> Self {
11059        Self {
11060            enabled: true,
11061            statutory_rate: default_statutory_rate(),
11062            uncertain_positions: true,
11063        }
11064    }
11065}
11066
11067/// Payroll tax configuration.
11068///
11069/// Controls generation of payroll tax data (employer/employee contributions,
11070/// social security, Medicare, etc.).
11071#[derive(Debug, Clone, Default, Serialize, Deserialize)]
11072pub struct PayrollTaxSchemaConfig {
11073    /// Whether payroll tax generation is enabled.
11074    #[serde(default)]
11075    pub enabled: bool,
11076}
11077
11078// ---------------------------------------------------------------------------
11079// Treasury & Cash Management Configuration
11080// ---------------------------------------------------------------------------
11081
11082/// Treasury and cash management configuration.
11083///
11084/// Controls generation of cash positions, forecasts, pooling, hedging
11085/// instruments (ASC 815 / IFRS 9), debt instruments with covenants,
11086/// bank guarantees, and intercompany netting runs.
11087#[derive(Debug, Clone, Serialize, Deserialize)]
11088pub struct TreasuryConfig {
11089    /// Whether treasury generation is enabled.
11090    #[serde(default)]
11091    pub enabled: bool,
11092    /// Cash positioning configuration.
11093    #[serde(default)]
11094    pub cash_positioning: CashPositioningConfig,
11095    /// Cash forecasting configuration.
11096    #[serde(default)]
11097    pub cash_forecasting: CashForecastingConfig,
11098    /// Cash pooling configuration.
11099    #[serde(default)]
11100    pub cash_pooling: CashPoolingConfig,
11101    /// Hedging configuration (FX forwards, IR swaps, etc.).
11102    #[serde(default)]
11103    pub hedging: HedgingSchemaConfig,
11104    /// Debt instrument and covenant configuration.
11105    #[serde(default)]
11106    pub debt: DebtSchemaConfig,
11107    /// Intercompany netting configuration.
11108    #[serde(default)]
11109    pub netting: NettingSchemaConfig,
11110    /// Bank guarantee / letter of credit configuration.
11111    #[serde(default)]
11112    pub bank_guarantees: BankGuaranteeSchemaConfig,
11113    /// Anomaly injection rate for treasury data (0.0 to 1.0).
11114    #[serde(default = "default_treasury_anomaly_rate")]
11115    pub anomaly_rate: f64,
11116}
11117
11118fn default_treasury_anomaly_rate() -> f64 {
11119    0.02
11120}
11121
11122impl Default for TreasuryConfig {
11123    fn default() -> Self {
11124        Self {
11125            enabled: false,
11126            cash_positioning: CashPositioningConfig::default(),
11127            cash_forecasting: CashForecastingConfig::default(),
11128            cash_pooling: CashPoolingConfig::default(),
11129            hedging: HedgingSchemaConfig::default(),
11130            debt: DebtSchemaConfig::default(),
11131            netting: NettingSchemaConfig::default(),
11132            bank_guarantees: BankGuaranteeSchemaConfig::default(),
11133            anomaly_rate: default_treasury_anomaly_rate(),
11134        }
11135    }
11136}
11137
11138/// Cash positioning configuration.
11139///
11140/// Controls daily cash position generation per entity/bank account.
11141#[derive(Debug, Clone, Serialize, Deserialize)]
11142pub struct CashPositioningConfig {
11143    /// Whether cash positioning is enabled.
11144    #[serde(default = "default_true")]
11145    pub enabled: bool,
11146    /// Position generation frequency.
11147    #[serde(default = "default_cash_frequency")]
11148    pub frequency: String,
11149    /// Minimum cash balance policy threshold.
11150    #[serde(default = "default_minimum_balance_policy")]
11151    pub minimum_balance_policy: f64,
11152}
11153
11154fn default_cash_frequency() -> String {
11155    "daily".to_string()
11156}
11157
11158fn default_minimum_balance_policy() -> f64 {
11159    100_000.0
11160}
11161
11162impl Default for CashPositioningConfig {
11163    fn default() -> Self {
11164        Self {
11165            enabled: true,
11166            frequency: default_cash_frequency(),
11167            minimum_balance_policy: default_minimum_balance_policy(),
11168        }
11169    }
11170}
11171
11172/// Cash forecasting configuration.
11173///
11174/// Controls forward-looking cash forecast generation with probability-weighted items.
11175#[derive(Debug, Clone, Serialize, Deserialize)]
11176pub struct CashForecastingConfig {
11177    /// Whether cash forecasting is enabled.
11178    #[serde(default = "default_true")]
11179    pub enabled: bool,
11180    /// Number of days to forecast into the future.
11181    #[serde(default = "default_horizon_days")]
11182    pub horizon_days: u32,
11183    /// AR collection probability curve type ("aging" or "flat").
11184    #[serde(default = "default_ar_probability_curve")]
11185    pub ar_collection_probability_curve: String,
11186    /// Confidence interval for the forecast (0.0 to 1.0).
11187    #[serde(default = "default_confidence_interval")]
11188    pub confidence_interval: f64,
11189}
11190
11191fn default_horizon_days() -> u32 {
11192    90
11193}
11194
11195fn default_ar_probability_curve() -> String {
11196    "aging".to_string()
11197}
11198
11199fn default_confidence_interval() -> f64 {
11200    0.90
11201}
11202
11203impl Default for CashForecastingConfig {
11204    fn default() -> Self {
11205        Self {
11206            enabled: true,
11207            horizon_days: default_horizon_days(),
11208            ar_collection_probability_curve: default_ar_probability_curve(),
11209            confidence_interval: default_confidence_interval(),
11210        }
11211    }
11212}
11213
11214/// Cash pooling configuration.
11215///
11216/// Controls cash pool structure generation (physical, notional, zero-balancing).
11217#[derive(Debug, Clone, Serialize, Deserialize)]
11218pub struct CashPoolingConfig {
11219    /// Whether cash pooling is enabled.
11220    #[serde(default)]
11221    pub enabled: bool,
11222    /// Pool type: "physical_pooling", "notional_pooling", or "zero_balancing".
11223    #[serde(default = "default_pool_type")]
11224    pub pool_type: String,
11225    /// Time of day when sweeps occur (HH:MM format).
11226    #[serde(default = "default_sweep_time")]
11227    pub sweep_time: String,
11228}
11229
11230fn default_pool_type() -> String {
11231    "zero_balancing".to_string()
11232}
11233
11234fn default_sweep_time() -> String {
11235    "16:00".to_string()
11236}
11237
11238impl Default for CashPoolingConfig {
11239    fn default() -> Self {
11240        Self {
11241            enabled: false,
11242            pool_type: default_pool_type(),
11243            sweep_time: default_sweep_time(),
11244        }
11245    }
11246}
11247
11248/// Hedging configuration.
11249///
11250/// Controls generation of hedging instruments and hedge relationship designations
11251/// under ASC 815 / IFRS 9.
11252#[derive(Debug, Clone, Serialize, Deserialize)]
11253pub struct HedgingSchemaConfig {
11254    /// Whether hedging generation is enabled.
11255    #[serde(default)]
11256    pub enabled: bool,
11257    /// Target hedge ratio (0.0 to 1.0). Proportion of FX exposure to hedge.
11258    #[serde(default = "default_hedge_ratio")]
11259    pub hedge_ratio: f64,
11260    /// Types of instruments to generate (e.g., ["fx_forward", "interest_rate_swap"]).
11261    #[serde(default = "default_hedge_instruments")]
11262    pub instruments: Vec<String>,
11263    /// Whether to designate formal hedge accounting relationships.
11264    #[serde(default = "default_true")]
11265    pub hedge_accounting: bool,
11266    /// Effectiveness testing method: "dollar_offset", "regression", or "critical_terms".
11267    #[serde(default = "default_effectiveness_method")]
11268    pub effectiveness_method: String,
11269}
11270
11271fn default_hedge_ratio() -> f64 {
11272    0.75
11273}
11274
11275fn default_hedge_instruments() -> Vec<String> {
11276    vec!["fx_forward".to_string(), "interest_rate_swap".to_string()]
11277}
11278
11279fn default_effectiveness_method() -> String {
11280    "regression".to_string()
11281}
11282
11283impl Default for HedgingSchemaConfig {
11284    fn default() -> Self {
11285        Self {
11286            enabled: false,
11287            hedge_ratio: default_hedge_ratio(),
11288            instruments: default_hedge_instruments(),
11289            hedge_accounting: true,
11290            effectiveness_method: default_effectiveness_method(),
11291        }
11292    }
11293}
11294
11295/// Debt instrument configuration.
11296///
11297/// Controls generation of debt instruments (term loans, revolving credit, bonds)
11298/// with amortization schedules and financial covenants.
11299#[derive(Debug, Clone, Default, Serialize, Deserialize)]
11300pub struct DebtSchemaConfig {
11301    /// Whether debt instrument generation is enabled.
11302    #[serde(default)]
11303    pub enabled: bool,
11304    /// Debt instrument definitions.
11305    #[serde(default)]
11306    pub instruments: Vec<DebtInstrumentDef>,
11307    /// Covenant definitions.
11308    #[serde(default)]
11309    pub covenants: Vec<CovenantDef>,
11310}
11311
11312/// Definition of a debt instrument in configuration.
11313#[derive(Debug, Clone, Serialize, Deserialize)]
11314pub struct DebtInstrumentDef {
11315    /// Instrument type: "term_loan", "revolving_credit", "bond", "commercial_paper", "bridge_loan".
11316    #[serde(rename = "type")]
11317    pub instrument_type: String,
11318    /// Principal amount (for term loans, bonds).
11319    #[serde(default)]
11320    pub principal: Option<f64>,
11321    /// Interest rate (annual, as decimal fraction).
11322    #[serde(default)]
11323    pub rate: Option<f64>,
11324    /// Maturity in months.
11325    #[serde(default)]
11326    pub maturity_months: Option<u32>,
11327    /// Facility limit (for revolving credit).
11328    #[serde(default)]
11329    pub facility: Option<f64>,
11330}
11331
11332/// Definition of a debt covenant in configuration.
11333#[derive(Debug, Clone, Serialize, Deserialize)]
11334pub struct CovenantDef {
11335    /// Covenant type: "debt_to_equity", "interest_coverage", "current_ratio",
11336    /// "net_worth", "debt_to_ebitda", "fixed_charge_coverage".
11337    #[serde(rename = "type")]
11338    pub covenant_type: String,
11339    /// Covenant threshold value.
11340    pub threshold: f64,
11341}
11342
11343/// Intercompany netting configuration.
11344///
11345/// Controls generation of multilateral netting runs.
11346#[derive(Debug, Clone, Serialize, Deserialize)]
11347pub struct NettingSchemaConfig {
11348    /// Whether netting generation is enabled.
11349    #[serde(default)]
11350    pub enabled: bool,
11351    /// Netting cycle: "daily", "weekly", or "monthly".
11352    #[serde(default = "default_netting_cycle")]
11353    pub cycle: String,
11354}
11355
11356fn default_netting_cycle() -> String {
11357    "monthly".to_string()
11358}
11359
11360impl Default for NettingSchemaConfig {
11361    fn default() -> Self {
11362        Self {
11363            enabled: false,
11364            cycle: default_netting_cycle(),
11365        }
11366    }
11367}
11368
11369/// Bank guarantee and letter of credit configuration.
11370///
11371/// Controls generation of bank guarantees, standby LCs, and performance bonds.
11372#[derive(Debug, Clone, Serialize, Deserialize)]
11373pub struct BankGuaranteeSchemaConfig {
11374    /// Whether bank guarantee generation is enabled.
11375    #[serde(default)]
11376    pub enabled: bool,
11377    /// Number of guarantees to generate.
11378    #[serde(default = "default_guarantee_count")]
11379    pub count: u32,
11380}
11381
11382fn default_guarantee_count() -> u32 {
11383    5
11384}
11385
11386impl Default for BankGuaranteeSchemaConfig {
11387    fn default() -> Self {
11388        Self {
11389            enabled: false,
11390            count: default_guarantee_count(),
11391        }
11392    }
11393}
11394
11395// ===========================================================================
11396// Project Accounting Configuration
11397// ===========================================================================
11398
11399/// Project accounting configuration.
11400///
11401/// Controls generation of project cost lines, revenue recognition,
11402/// milestones, change orders, retainage, and earned value metrics.
11403#[derive(Debug, Clone, Serialize, Deserialize)]
11404pub struct ProjectAccountingConfig {
11405    /// Whether project accounting is enabled.
11406    #[serde(default)]
11407    pub enabled: bool,
11408    /// Number of projects to generate.
11409    #[serde(default = "default_project_count")]
11410    pub project_count: u32,
11411    /// Distribution of project types (capital, internal, customer, r_and_d, maintenance, technology).
11412    #[serde(default)]
11413    pub project_types: ProjectTypeDistribution,
11414    /// WBS structure configuration.
11415    #[serde(default)]
11416    pub wbs: WbsSchemaConfig,
11417    /// Cost allocation rates (what % of source documents get project-tagged).
11418    #[serde(default)]
11419    pub cost_allocation: CostAllocationConfig,
11420    /// Revenue recognition configuration for project accounting.
11421    #[serde(default)]
11422    pub revenue_recognition: ProjectRevenueRecognitionConfig,
11423    /// Milestone configuration.
11424    #[serde(default)]
11425    pub milestones: MilestoneSchemaConfig,
11426    /// Change order configuration.
11427    #[serde(default)]
11428    pub change_orders: ChangeOrderSchemaConfig,
11429    /// Retainage configuration.
11430    #[serde(default)]
11431    pub retainage: RetainageSchemaConfig,
11432    /// Earned value management configuration.
11433    #[serde(default)]
11434    pub earned_value: EarnedValueSchemaConfig,
11435    /// Anomaly injection rate for project accounting data (0.0 to 1.0).
11436    #[serde(default = "default_project_anomaly_rate")]
11437    pub anomaly_rate: f64,
11438}
11439
11440fn default_project_count() -> u32 {
11441    10
11442}
11443
11444fn default_project_anomaly_rate() -> f64 {
11445    0.03
11446}
11447
11448impl Default for ProjectAccountingConfig {
11449    fn default() -> Self {
11450        Self {
11451            enabled: false,
11452            project_count: default_project_count(),
11453            project_types: ProjectTypeDistribution::default(),
11454            wbs: WbsSchemaConfig::default(),
11455            cost_allocation: CostAllocationConfig::default(),
11456            revenue_recognition: ProjectRevenueRecognitionConfig::default(),
11457            milestones: MilestoneSchemaConfig::default(),
11458            change_orders: ChangeOrderSchemaConfig::default(),
11459            retainage: RetainageSchemaConfig::default(),
11460            earned_value: EarnedValueSchemaConfig::default(),
11461            anomaly_rate: default_project_anomaly_rate(),
11462        }
11463    }
11464}
11465
11466/// Distribution of project types by weight.
11467#[derive(Debug, Clone, Serialize, Deserialize)]
11468pub struct ProjectTypeDistribution {
11469    /// Weight for capital projects (default 0.25).
11470    #[serde(default = "default_capital_weight")]
11471    pub capital: f64,
11472    /// Weight for internal projects (default 0.20).
11473    #[serde(default = "default_internal_weight")]
11474    pub internal: f64,
11475    /// Weight for customer projects (default 0.30).
11476    #[serde(default = "default_customer_weight")]
11477    pub customer: f64,
11478    /// Weight for R&D projects (default 0.10).
11479    #[serde(default = "default_rnd_weight")]
11480    pub r_and_d: f64,
11481    /// Weight for maintenance projects (default 0.10).
11482    #[serde(default = "default_maintenance_weight")]
11483    pub maintenance: f64,
11484    /// Weight for technology projects (default 0.05).
11485    #[serde(default = "default_technology_weight")]
11486    pub technology: f64,
11487}
11488
11489fn default_capital_weight() -> f64 {
11490    0.25
11491}
11492fn default_internal_weight() -> f64 {
11493    0.20
11494}
11495fn default_customer_weight() -> f64 {
11496    0.30
11497}
11498fn default_rnd_weight() -> f64 {
11499    0.10
11500}
11501fn default_maintenance_weight() -> f64 {
11502    0.10
11503}
11504fn default_technology_weight() -> f64 {
11505    0.05
11506}
11507
11508impl Default for ProjectTypeDistribution {
11509    fn default() -> Self {
11510        Self {
11511            capital: default_capital_weight(),
11512            internal: default_internal_weight(),
11513            customer: default_customer_weight(),
11514            r_and_d: default_rnd_weight(),
11515            maintenance: default_maintenance_weight(),
11516            technology: default_technology_weight(),
11517        }
11518    }
11519}
11520
11521/// WBS structure configuration.
11522#[derive(Debug, Clone, Serialize, Deserialize)]
11523pub struct WbsSchemaConfig {
11524    /// Maximum depth of WBS hierarchy (default 3).
11525    #[serde(default = "default_wbs_max_depth")]
11526    pub max_depth: u32,
11527    /// Minimum elements per level-1 WBS (default 2).
11528    #[serde(default = "default_wbs_min_elements")]
11529    pub min_elements_per_level: u32,
11530    /// Maximum elements per level-1 WBS (default 6).
11531    #[serde(default = "default_wbs_max_elements")]
11532    pub max_elements_per_level: u32,
11533}
11534
11535fn default_wbs_max_depth() -> u32 {
11536    3
11537}
11538fn default_wbs_min_elements() -> u32 {
11539    2
11540}
11541fn default_wbs_max_elements() -> u32 {
11542    6
11543}
11544
11545impl Default for WbsSchemaConfig {
11546    fn default() -> Self {
11547        Self {
11548            max_depth: default_wbs_max_depth(),
11549            min_elements_per_level: default_wbs_min_elements(),
11550            max_elements_per_level: default_wbs_max_elements(),
11551        }
11552    }
11553}
11554
11555/// Cost allocation rates — what fraction of each document type gets linked to a project.
11556#[derive(Debug, Clone, Serialize, Deserialize)]
11557pub struct CostAllocationConfig {
11558    /// Fraction of time entries assigned to projects (0.0 to 1.0).
11559    #[serde(default = "default_time_entry_rate")]
11560    pub time_entry_project_rate: f64,
11561    /// Fraction of expense reports assigned to projects (0.0 to 1.0).
11562    #[serde(default = "default_expense_rate")]
11563    pub expense_project_rate: f64,
11564    /// Fraction of purchase orders assigned to projects (0.0 to 1.0).
11565    #[serde(default = "default_po_rate")]
11566    pub purchase_order_project_rate: f64,
11567    /// Fraction of vendor invoices assigned to projects (0.0 to 1.0).
11568    #[serde(default = "default_vi_rate")]
11569    pub vendor_invoice_project_rate: f64,
11570}
11571
11572fn default_time_entry_rate() -> f64 {
11573    0.60
11574}
11575fn default_expense_rate() -> f64 {
11576    0.30
11577}
11578fn default_po_rate() -> f64 {
11579    0.40
11580}
11581fn default_vi_rate() -> f64 {
11582    0.35
11583}
11584
11585impl Default for CostAllocationConfig {
11586    fn default() -> Self {
11587        Self {
11588            time_entry_project_rate: default_time_entry_rate(),
11589            expense_project_rate: default_expense_rate(),
11590            purchase_order_project_rate: default_po_rate(),
11591            vendor_invoice_project_rate: default_vi_rate(),
11592        }
11593    }
11594}
11595
11596/// Revenue recognition configuration for project accounting.
11597#[derive(Debug, Clone, Serialize, Deserialize)]
11598pub struct ProjectRevenueRecognitionConfig {
11599    /// Whether revenue recognition is enabled for customer projects.
11600    #[serde(default = "default_true")]
11601    pub enabled: bool,
11602    /// Default method: "percentage_of_completion", "completed_contract", "milestone_based".
11603    #[serde(default = "default_revenue_method")]
11604    pub method: String,
11605    /// Default completion measure: "cost_to_cost", "labor_hours", "physical_completion".
11606    #[serde(default = "default_completion_measure")]
11607    pub completion_measure: String,
11608    /// Average contract value for customer projects.
11609    #[serde(default = "default_avg_contract_value")]
11610    pub avg_contract_value: f64,
11611}
11612
11613fn default_revenue_method() -> String {
11614    "percentage_of_completion".to_string()
11615}
11616fn default_completion_measure() -> String {
11617    "cost_to_cost".to_string()
11618}
11619fn default_avg_contract_value() -> f64 {
11620    500_000.0
11621}
11622
11623impl Default for ProjectRevenueRecognitionConfig {
11624    fn default() -> Self {
11625        Self {
11626            enabled: true,
11627            method: default_revenue_method(),
11628            completion_measure: default_completion_measure(),
11629            avg_contract_value: default_avg_contract_value(),
11630        }
11631    }
11632}
11633
11634/// Milestone configuration.
11635#[derive(Debug, Clone, Serialize, Deserialize)]
11636pub struct MilestoneSchemaConfig {
11637    /// Whether milestone generation is enabled.
11638    #[serde(default = "default_true")]
11639    pub enabled: bool,
11640    /// Average number of milestones per project.
11641    #[serde(default = "default_milestones_per_project")]
11642    pub avg_per_project: u32,
11643    /// Fraction of milestones that are payment milestones (0.0 to 1.0).
11644    #[serde(default = "default_payment_milestone_rate")]
11645    pub payment_milestone_rate: f64,
11646}
11647
11648fn default_milestones_per_project() -> u32 {
11649    4
11650}
11651fn default_payment_milestone_rate() -> f64 {
11652    0.50
11653}
11654
11655impl Default for MilestoneSchemaConfig {
11656    fn default() -> Self {
11657        Self {
11658            enabled: true,
11659            avg_per_project: default_milestones_per_project(),
11660            payment_milestone_rate: default_payment_milestone_rate(),
11661        }
11662    }
11663}
11664
11665/// Change order configuration.
11666#[derive(Debug, Clone, Serialize, Deserialize)]
11667pub struct ChangeOrderSchemaConfig {
11668    /// Whether change order generation is enabled.
11669    #[serde(default = "default_true")]
11670    pub enabled: bool,
11671    /// Probability that a project will have at least one change order (0.0 to 1.0).
11672    #[serde(default = "default_change_order_probability")]
11673    pub probability: f64,
11674    /// Maximum change orders per project.
11675    #[serde(default = "default_max_change_orders")]
11676    pub max_per_project: u32,
11677    /// Approval rate for change orders (0.0 to 1.0).
11678    #[serde(default = "default_change_order_approval_rate")]
11679    pub approval_rate: f64,
11680}
11681
11682fn default_change_order_probability() -> f64 {
11683    0.40
11684}
11685fn default_max_change_orders() -> u32 {
11686    3
11687}
11688fn default_change_order_approval_rate() -> f64 {
11689    0.75
11690}
11691
11692impl Default for ChangeOrderSchemaConfig {
11693    fn default() -> Self {
11694        Self {
11695            enabled: true,
11696            probability: default_change_order_probability(),
11697            max_per_project: default_max_change_orders(),
11698            approval_rate: default_change_order_approval_rate(),
11699        }
11700    }
11701}
11702
11703/// Retainage configuration.
11704#[derive(Debug, Clone, Serialize, Deserialize)]
11705pub struct RetainageSchemaConfig {
11706    /// Whether retainage is enabled.
11707    #[serde(default)]
11708    pub enabled: bool,
11709    /// Default retainage percentage (0.0 to 1.0, e.g., 0.10 for 10%).
11710    #[serde(default = "default_retainage_pct")]
11711    pub default_percentage: f64,
11712}
11713
11714fn default_retainage_pct() -> f64 {
11715    0.10
11716}
11717
11718impl Default for RetainageSchemaConfig {
11719    fn default() -> Self {
11720        Self {
11721            enabled: false,
11722            default_percentage: default_retainage_pct(),
11723        }
11724    }
11725}
11726
11727/// Earned value management (EVM) configuration.
11728#[derive(Debug, Clone, Serialize, Deserialize)]
11729pub struct EarnedValueSchemaConfig {
11730    /// Whether EVM metrics are generated.
11731    #[serde(default = "default_true")]
11732    pub enabled: bool,
11733    /// Measurement frequency: "weekly", "biweekly", "monthly".
11734    #[serde(default = "default_evm_frequency")]
11735    pub frequency: String,
11736}
11737
11738fn default_evm_frequency() -> String {
11739    "monthly".to_string()
11740}
11741
11742impl Default for EarnedValueSchemaConfig {
11743    fn default() -> Self {
11744        Self {
11745            enabled: true,
11746            frequency: default_evm_frequency(),
11747        }
11748    }
11749}
11750
11751// =============================================================================
11752// ESG / Sustainability Configuration
11753// =============================================================================
11754
11755/// Top-level ESG / sustainability reporting configuration.
11756#[derive(Debug, Clone, Serialize, Deserialize)]
11757pub struct EsgConfig {
11758    /// Whether ESG generation is enabled.
11759    #[serde(default)]
11760    pub enabled: bool,
11761    /// Environmental metrics (emissions, energy, water, waste).
11762    #[serde(default)]
11763    pub environmental: EnvironmentalConfig,
11764    /// Social metrics (diversity, pay equity, safety).
11765    #[serde(default)]
11766    pub social: SocialConfig,
11767    /// Governance metrics (board composition, ethics, compliance).
11768    #[serde(default)]
11769    pub governance: GovernanceSchemaConfig,
11770    /// Supply-chain ESG assessment settings.
11771    #[serde(default)]
11772    pub supply_chain_esg: SupplyChainEsgConfig,
11773    /// ESG reporting / disclosure framework settings.
11774    #[serde(default)]
11775    pub reporting: EsgReportingConfig,
11776    /// Climate scenario analysis settings.
11777    #[serde(default)]
11778    pub climate_scenarios: ClimateScenarioConfig,
11779    /// Anomaly injection rate for ESG data (0.0 to 1.0).
11780    #[serde(default = "default_esg_anomaly_rate")]
11781    pub anomaly_rate: f64,
11782}
11783
11784fn default_esg_anomaly_rate() -> f64 {
11785    0.02
11786}
11787
11788impl Default for EsgConfig {
11789    fn default() -> Self {
11790        Self {
11791            enabled: false,
11792            environmental: EnvironmentalConfig::default(),
11793            social: SocialConfig::default(),
11794            governance: GovernanceSchemaConfig::default(),
11795            supply_chain_esg: SupplyChainEsgConfig::default(),
11796            reporting: EsgReportingConfig::default(),
11797            climate_scenarios: ClimateScenarioConfig::default(),
11798            anomaly_rate: default_esg_anomaly_rate(),
11799        }
11800    }
11801}
11802
11803/// Country pack configuration.
11804///
11805/// Controls where to load additional country packs and per-country overrides.
11806/// When omitted, only the built-in packs (_default, US, DE, GB) are used.
11807#[derive(Debug, Clone, Serialize, Deserialize, Default)]
11808pub struct CountryPacksSchemaConfig {
11809    /// Optional directory containing additional `*.json` country packs.
11810    #[serde(default)]
11811    pub external_dir: Option<PathBuf>,
11812    /// Per-country overrides applied after loading.
11813    /// Keys are ISO 3166-1 alpha-2 codes; values are partial JSON objects
11814    /// that are deep-merged on top of the loaded pack.
11815    #[serde(default)]
11816    pub overrides: std::collections::HashMap<String, serde_json::Value>,
11817}
11818
11819/// Environmental metrics configuration.
11820#[derive(Debug, Clone, Serialize, Deserialize)]
11821pub struct EnvironmentalConfig {
11822    /// Whether environmental metrics are generated.
11823    #[serde(default = "default_true")]
11824    pub enabled: bool,
11825    /// Scope 1 (direct) emission generation settings.
11826    #[serde(default)]
11827    pub scope1: EmissionScopeConfig,
11828    /// Scope 2 (purchased energy) emission generation settings.
11829    #[serde(default)]
11830    pub scope2: EmissionScopeConfig,
11831    /// Scope 3 (value chain) emission generation settings.
11832    #[serde(default)]
11833    pub scope3: Scope3Config,
11834    /// Energy consumption tracking settings.
11835    #[serde(default)]
11836    pub energy: EnergySchemaConfig,
11837    /// Water usage tracking settings.
11838    #[serde(default)]
11839    pub water: WaterSchemaConfig,
11840    /// Waste management tracking settings.
11841    #[serde(default)]
11842    pub waste: WasteSchemaConfig,
11843}
11844
11845impl Default for EnvironmentalConfig {
11846    fn default() -> Self {
11847        Self {
11848            enabled: true,
11849            scope1: EmissionScopeConfig::default(),
11850            scope2: EmissionScopeConfig::default(),
11851            scope3: Scope3Config::default(),
11852            energy: EnergySchemaConfig::default(),
11853            water: WaterSchemaConfig::default(),
11854            waste: WasteSchemaConfig::default(),
11855        }
11856    }
11857}
11858
11859/// Configuration for a single emission scope (Scope 1 or 2).
11860#[derive(Debug, Clone, Serialize, Deserialize)]
11861pub struct EmissionScopeConfig {
11862    /// Whether this scope is enabled.
11863    #[serde(default = "default_true")]
11864    pub enabled: bool,
11865    /// Emission factor region (e.g., "US", "EU", "global").
11866    #[serde(default = "default_emission_region")]
11867    pub factor_region: String,
11868}
11869
11870fn default_emission_region() -> String {
11871    "US".to_string()
11872}
11873
11874impl Default for EmissionScopeConfig {
11875    fn default() -> Self {
11876        Self {
11877            enabled: true,
11878            factor_region: default_emission_region(),
11879        }
11880    }
11881}
11882
11883/// Scope 3 (value chain) emission configuration.
11884#[derive(Debug, Clone, Serialize, Deserialize)]
11885pub struct Scope3Config {
11886    /// Whether Scope 3 emissions are generated.
11887    #[serde(default = "default_true")]
11888    pub enabled: bool,
11889    /// Categories to include (e.g., "purchased_goods", "business_travel", "commuting").
11890    #[serde(default = "default_scope3_categories")]
11891    pub categories: Vec<String>,
11892    /// Spend-based emission intensity (kg CO2e per USD).
11893    #[serde(default = "default_spend_intensity")]
11894    pub default_spend_intensity_kg_per_usd: f64,
11895}
11896
11897fn default_scope3_categories() -> Vec<String> {
11898    vec![
11899        "purchased_goods".to_string(),
11900        "business_travel".to_string(),
11901        "employee_commuting".to_string(),
11902    ]
11903}
11904
11905fn default_spend_intensity() -> f64 {
11906    0.5
11907}
11908
11909impl Default for Scope3Config {
11910    fn default() -> Self {
11911        Self {
11912            enabled: true,
11913            categories: default_scope3_categories(),
11914            default_spend_intensity_kg_per_usd: default_spend_intensity(),
11915        }
11916    }
11917}
11918
11919/// Energy consumption configuration.
11920#[derive(Debug, Clone, Serialize, Deserialize)]
11921pub struct EnergySchemaConfig {
11922    /// Whether energy consumption tracking is enabled.
11923    #[serde(default = "default_true")]
11924    pub enabled: bool,
11925    /// Number of facilities to generate.
11926    #[serde(default = "default_facility_count")]
11927    pub facility_count: u32,
11928    /// Target percentage of energy from renewable sources (0.0 to 1.0).
11929    #[serde(default = "default_renewable_target")]
11930    pub renewable_target: f64,
11931}
11932
11933fn default_facility_count() -> u32 {
11934    5
11935}
11936
11937fn default_renewable_target() -> f64 {
11938    0.30
11939}
11940
11941impl Default for EnergySchemaConfig {
11942    fn default() -> Self {
11943        Self {
11944            enabled: true,
11945            facility_count: default_facility_count(),
11946            renewable_target: default_renewable_target(),
11947        }
11948    }
11949}
11950
11951/// Water usage configuration.
11952#[derive(Debug, Clone, Serialize, Deserialize)]
11953pub struct WaterSchemaConfig {
11954    /// Whether water usage tracking is enabled.
11955    #[serde(default = "default_true")]
11956    pub enabled: bool,
11957    /// Number of facilities with water tracking.
11958    #[serde(default = "default_water_facility_count")]
11959    pub facility_count: u32,
11960}
11961
11962fn default_water_facility_count() -> u32 {
11963    3
11964}
11965
11966impl Default for WaterSchemaConfig {
11967    fn default() -> Self {
11968        Self {
11969            enabled: true,
11970            facility_count: default_water_facility_count(),
11971        }
11972    }
11973}
11974
11975/// Waste management configuration.
11976#[derive(Debug, Clone, Serialize, Deserialize)]
11977pub struct WasteSchemaConfig {
11978    /// Whether waste tracking is enabled.
11979    #[serde(default = "default_true")]
11980    pub enabled: bool,
11981    /// Target diversion rate (0.0 to 1.0).
11982    #[serde(default = "default_diversion_target")]
11983    pub diversion_target: f64,
11984}
11985
11986fn default_diversion_target() -> f64 {
11987    0.50
11988}
11989
11990impl Default for WasteSchemaConfig {
11991    fn default() -> Self {
11992        Self {
11993            enabled: true,
11994            diversion_target: default_diversion_target(),
11995        }
11996    }
11997}
11998
11999/// Social metrics configuration.
12000#[derive(Debug, Clone, Serialize, Deserialize)]
12001pub struct SocialConfig {
12002    /// Whether social metrics are generated.
12003    #[serde(default = "default_true")]
12004    pub enabled: bool,
12005    /// Workforce diversity tracking settings.
12006    #[serde(default)]
12007    pub diversity: DiversitySchemaConfig,
12008    /// Pay equity analysis settings.
12009    #[serde(default)]
12010    pub pay_equity: PayEquitySchemaConfig,
12011    /// Safety incident and metrics settings.
12012    #[serde(default)]
12013    pub safety: SafetySchemaConfig,
12014}
12015
12016impl Default for SocialConfig {
12017    fn default() -> Self {
12018        Self {
12019            enabled: true,
12020            diversity: DiversitySchemaConfig::default(),
12021            pay_equity: PayEquitySchemaConfig::default(),
12022            safety: SafetySchemaConfig::default(),
12023        }
12024    }
12025}
12026
12027/// Workforce diversity configuration.
12028#[derive(Debug, Clone, Serialize, Deserialize)]
12029pub struct DiversitySchemaConfig {
12030    /// Whether diversity metrics are generated.
12031    #[serde(default = "default_true")]
12032    pub enabled: bool,
12033    /// Dimensions to track (e.g., "gender", "ethnicity", "age_group").
12034    #[serde(default = "default_diversity_dimensions")]
12035    pub dimensions: Vec<String>,
12036}
12037
12038fn default_diversity_dimensions() -> Vec<String> {
12039    vec![
12040        "gender".to_string(),
12041        "ethnicity".to_string(),
12042        "age_group".to_string(),
12043    ]
12044}
12045
12046impl Default for DiversitySchemaConfig {
12047    fn default() -> Self {
12048        Self {
12049            enabled: true,
12050            dimensions: default_diversity_dimensions(),
12051        }
12052    }
12053}
12054
12055/// Pay equity analysis configuration.
12056#[derive(Debug, Clone, Serialize, Deserialize)]
12057pub struct PayEquitySchemaConfig {
12058    /// Whether pay equity analysis is generated.
12059    #[serde(default = "default_true")]
12060    pub enabled: bool,
12061    /// Target pay gap threshold for flagging (e.g., 0.05 = 5% gap).
12062    #[serde(default = "default_pay_gap_threshold")]
12063    pub gap_threshold: f64,
12064}
12065
12066fn default_pay_gap_threshold() -> f64 {
12067    0.05
12068}
12069
12070impl Default for PayEquitySchemaConfig {
12071    fn default() -> Self {
12072        Self {
12073            enabled: true,
12074            gap_threshold: default_pay_gap_threshold(),
12075        }
12076    }
12077}
12078
12079/// Safety metrics configuration.
12080#[derive(Debug, Clone, Serialize, Deserialize)]
12081pub struct SafetySchemaConfig {
12082    /// Whether safety metrics are generated.
12083    #[serde(default = "default_true")]
12084    pub enabled: bool,
12085    /// Average annual recordable incidents per 200,000 hours.
12086    #[serde(default = "default_trir_target")]
12087    pub target_trir: f64,
12088    /// Number of safety incidents to generate.
12089    #[serde(default = "default_incident_count")]
12090    pub incident_count: u32,
12091}
12092
12093fn default_trir_target() -> f64 {
12094    2.5
12095}
12096
12097fn default_incident_count() -> u32 {
12098    20
12099}
12100
12101impl Default for SafetySchemaConfig {
12102    fn default() -> Self {
12103        Self {
12104            enabled: true,
12105            target_trir: default_trir_target(),
12106            incident_count: default_incident_count(),
12107        }
12108    }
12109}
12110
12111/// Governance metrics configuration.
12112#[derive(Debug, Clone, Serialize, Deserialize)]
12113pub struct GovernanceSchemaConfig {
12114    /// Whether governance metrics are generated.
12115    #[serde(default = "default_true")]
12116    pub enabled: bool,
12117    /// Number of board members.
12118    #[serde(default = "default_board_size")]
12119    pub board_size: u32,
12120    /// Target independent director ratio (0.0 to 1.0).
12121    #[serde(default = "default_independence_target")]
12122    pub independence_target: f64,
12123}
12124
12125fn default_board_size() -> u32 {
12126    11
12127}
12128
12129fn default_independence_target() -> f64 {
12130    0.67
12131}
12132
12133impl Default for GovernanceSchemaConfig {
12134    fn default() -> Self {
12135        Self {
12136            enabled: true,
12137            board_size: default_board_size(),
12138            independence_target: default_independence_target(),
12139        }
12140    }
12141}
12142
12143/// Supply-chain ESG assessment configuration.
12144#[derive(Debug, Clone, Serialize, Deserialize)]
12145pub struct SupplyChainEsgConfig {
12146    /// Whether supply chain ESG assessments are generated.
12147    #[serde(default = "default_true")]
12148    pub enabled: bool,
12149    /// Proportion of vendors to assess (0.0 to 1.0).
12150    #[serde(default = "default_assessment_coverage")]
12151    pub assessment_coverage: f64,
12152    /// High-risk country codes for automatic flagging.
12153    #[serde(default = "default_high_risk_countries")]
12154    pub high_risk_countries: Vec<String>,
12155}
12156
12157fn default_assessment_coverage() -> f64 {
12158    0.80
12159}
12160
12161fn default_high_risk_countries() -> Vec<String> {
12162    vec!["CN".to_string(), "BD".to_string(), "MM".to_string()]
12163}
12164
12165impl Default for SupplyChainEsgConfig {
12166    fn default() -> Self {
12167        Self {
12168            enabled: true,
12169            assessment_coverage: default_assessment_coverage(),
12170            high_risk_countries: default_high_risk_countries(),
12171        }
12172    }
12173}
12174
12175/// ESG reporting / disclosure framework configuration.
12176#[derive(Debug, Clone, Serialize, Deserialize)]
12177pub struct EsgReportingConfig {
12178    /// Whether ESG disclosures are generated.
12179    #[serde(default = "default_true")]
12180    pub enabled: bool,
12181    /// Frameworks to generate disclosures for.
12182    #[serde(default = "default_esg_frameworks")]
12183    pub frameworks: Vec<String>,
12184    /// Whether materiality assessment is performed.
12185    #[serde(default = "default_true")]
12186    pub materiality_assessment: bool,
12187    /// Materiality threshold for impact dimension (0.0 to 1.0).
12188    #[serde(default = "default_materiality_threshold")]
12189    pub impact_threshold: f64,
12190    /// Materiality threshold for financial dimension (0.0 to 1.0).
12191    #[serde(default = "default_materiality_threshold")]
12192    pub financial_threshold: f64,
12193}
12194
12195fn default_esg_frameworks() -> Vec<String> {
12196    vec!["GRI".to_string(), "ESRS".to_string()]
12197}
12198
12199fn default_materiality_threshold() -> f64 {
12200    0.6
12201}
12202
12203impl Default for EsgReportingConfig {
12204    fn default() -> Self {
12205        Self {
12206            enabled: true,
12207            frameworks: default_esg_frameworks(),
12208            materiality_assessment: true,
12209            impact_threshold: default_materiality_threshold(),
12210            financial_threshold: default_materiality_threshold(),
12211        }
12212    }
12213}
12214
12215/// Climate scenario analysis configuration.
12216#[derive(Debug, Clone, Serialize, Deserialize)]
12217pub struct ClimateScenarioConfig {
12218    /// Whether climate scenario analysis is generated.
12219    #[serde(default)]
12220    pub enabled: bool,
12221    /// Scenarios to model (e.g., "net_zero_2050", "stated_policies", "current_trajectory").
12222    #[serde(default = "default_climate_scenarios")]
12223    pub scenarios: Vec<String>,
12224    /// Time horizons in years to project.
12225    #[serde(default = "default_time_horizons")]
12226    pub time_horizons: Vec<u32>,
12227}
12228
12229fn default_climate_scenarios() -> Vec<String> {
12230    vec![
12231        "net_zero_2050".to_string(),
12232        "stated_policies".to_string(),
12233        "current_trajectory".to_string(),
12234    ]
12235}
12236
12237fn default_time_horizons() -> Vec<u32> {
12238    vec![5, 10, 30]
12239}
12240
12241impl Default for ClimateScenarioConfig {
12242    fn default() -> Self {
12243        Self {
12244            enabled: false,
12245            scenarios: default_climate_scenarios(),
12246            time_horizons: default_time_horizons(),
12247        }
12248    }
12249}
12250
12251#[cfg(test)]
12252#[allow(clippy::unwrap_used)]
12253mod tests {
12254    use super::*;
12255    use crate::presets::demo_preset;
12256
12257    // ==========================================================================
12258    // Serialization/Deserialization Tests
12259    // ==========================================================================
12260
12261    #[test]
12262    fn test_config_yaml_roundtrip() {
12263        let config = demo_preset();
12264        let yaml = serde_yaml::to_string(&config).expect("Failed to serialize to YAML");
12265        let deserialized: GeneratorConfig =
12266            serde_yaml::from_str(&yaml).expect("Failed to deserialize from YAML");
12267
12268        assert_eq!(
12269            config.global.period_months,
12270            deserialized.global.period_months
12271        );
12272        assert_eq!(config.global.industry, deserialized.global.industry);
12273        assert_eq!(config.companies.len(), deserialized.companies.len());
12274        assert_eq!(config.companies[0].code, deserialized.companies[0].code);
12275    }
12276
12277    #[test]
12278    fn test_config_json_roundtrip() {
12279        // Create a config without infinity values (JSON can't serialize f64::INFINITY)
12280        let mut config = demo_preset();
12281        // Replace infinity with a large but finite value for JSON compatibility
12282        config.master_data.employees.approval_limits.executive = 1e12;
12283
12284        let json = serde_json::to_string(&config).expect("Failed to serialize to JSON");
12285        let deserialized: GeneratorConfig =
12286            serde_json::from_str(&json).expect("Failed to deserialize from JSON");
12287
12288        assert_eq!(
12289            config.global.period_months,
12290            deserialized.global.period_months
12291        );
12292        assert_eq!(config.global.industry, deserialized.global.industry);
12293        assert_eq!(config.companies.len(), deserialized.companies.len());
12294    }
12295
12296    #[test]
12297    fn test_transaction_volume_serialization() {
12298        // Test various transaction volumes serialize correctly
12299        let volumes = vec![
12300            (TransactionVolume::TenK, "ten_k"),
12301            (TransactionVolume::HundredK, "hundred_k"),
12302            (TransactionVolume::OneM, "one_m"),
12303            (TransactionVolume::TenM, "ten_m"),
12304            (TransactionVolume::HundredM, "hundred_m"),
12305        ];
12306
12307        for (volume, expected_key) in volumes {
12308            let json = serde_json::to_string(&volume).expect("Failed to serialize");
12309            assert!(
12310                json.contains(expected_key),
12311                "Expected {} in JSON: {}",
12312                expected_key,
12313                json
12314            );
12315        }
12316    }
12317
12318    #[test]
12319    fn test_transaction_volume_custom_serialization() {
12320        let volume = TransactionVolume::Custom(12345);
12321        let json = serde_json::to_string(&volume).expect("Failed to serialize");
12322        let deserialized: TransactionVolume =
12323            serde_json::from_str(&json).expect("Failed to deserialize");
12324        assert_eq!(deserialized.count(), 12345);
12325    }
12326
12327    #[test]
12328    fn test_output_mode_serialization() {
12329        let modes = vec![
12330            OutputMode::Streaming,
12331            OutputMode::FlatFile,
12332            OutputMode::Both,
12333        ];
12334
12335        for mode in modes {
12336            let json = serde_json::to_string(&mode).expect("Failed to serialize");
12337            let deserialized: OutputMode =
12338                serde_json::from_str(&json).expect("Failed to deserialize");
12339            assert!(format!("{:?}", mode) == format!("{:?}", deserialized));
12340        }
12341    }
12342
12343    #[test]
12344    fn test_file_format_serialization() {
12345        let formats = vec![
12346            FileFormat::Csv,
12347            FileFormat::Parquet,
12348            FileFormat::Json,
12349            FileFormat::JsonLines,
12350        ];
12351
12352        for format in formats {
12353            let json = serde_json::to_string(&format).expect("Failed to serialize");
12354            let deserialized: FileFormat =
12355                serde_json::from_str(&json).expect("Failed to deserialize");
12356            assert!(format!("{:?}", format) == format!("{:?}", deserialized));
12357        }
12358    }
12359
12360    #[test]
12361    fn test_compression_algorithm_serialization() {
12362        let algos = vec![
12363            CompressionAlgorithm::Gzip,
12364            CompressionAlgorithm::Zstd,
12365            CompressionAlgorithm::Lz4,
12366            CompressionAlgorithm::Snappy,
12367        ];
12368
12369        for algo in algos {
12370            let json = serde_json::to_string(&algo).expect("Failed to serialize");
12371            let deserialized: CompressionAlgorithm =
12372                serde_json::from_str(&json).expect("Failed to deserialize");
12373            assert!(format!("{:?}", algo) == format!("{:?}", deserialized));
12374        }
12375    }
12376
12377    #[test]
12378    fn test_transfer_pricing_method_serialization() {
12379        let methods = vec![
12380            TransferPricingMethod::CostPlus,
12381            TransferPricingMethod::ComparableUncontrolled,
12382            TransferPricingMethod::ResalePrice,
12383            TransferPricingMethod::TransactionalNetMargin,
12384            TransferPricingMethod::ProfitSplit,
12385        ];
12386
12387        for method in methods {
12388            let json = serde_json::to_string(&method).expect("Failed to serialize");
12389            let deserialized: TransferPricingMethod =
12390                serde_json::from_str(&json).expect("Failed to deserialize");
12391            assert!(format!("{:?}", method) == format!("{:?}", deserialized));
12392        }
12393    }
12394
12395    #[test]
12396    fn test_benford_exemption_serialization() {
12397        let exemptions = vec![
12398            BenfordExemption::Recurring,
12399            BenfordExemption::Payroll,
12400            BenfordExemption::FixedFees,
12401            BenfordExemption::RoundAmounts,
12402        ];
12403
12404        for exemption in exemptions {
12405            let json = serde_json::to_string(&exemption).expect("Failed to serialize");
12406            let deserialized: BenfordExemption =
12407                serde_json::from_str(&json).expect("Failed to deserialize");
12408            assert!(format!("{:?}", exemption) == format!("{:?}", deserialized));
12409        }
12410    }
12411
12412    // ==========================================================================
12413    // Default Value Tests
12414    // ==========================================================================
12415
12416    #[test]
12417    fn test_global_config_defaults() {
12418        let yaml = r#"
12419            industry: manufacturing
12420            start_date: "2024-01-01"
12421            period_months: 6
12422        "#;
12423        let config: GlobalConfig = serde_yaml::from_str(yaml).expect("Failed to parse");
12424        assert_eq!(config.group_currency, "USD");
12425        assert!(config.parallel);
12426        assert_eq!(config.worker_threads, 0);
12427        assert_eq!(config.memory_limit_mb, 0);
12428    }
12429
12430    #[test]
12431    fn test_fraud_config_defaults() {
12432        let config = FraudConfig::default();
12433        assert!(!config.enabled);
12434        assert_eq!(config.fraud_rate, 0.005);
12435        assert!(!config.clustering_enabled);
12436    }
12437
12438    #[test]
12439    fn test_internal_controls_config_defaults() {
12440        let config = InternalControlsConfig::default();
12441        assert!(!config.enabled);
12442        assert_eq!(config.exception_rate, 0.02);
12443        assert_eq!(config.sod_violation_rate, 0.01);
12444        assert!(config.export_control_master_data);
12445        assert_eq!(config.sox_materiality_threshold, 10000.0);
12446        // COSO fields
12447        assert!(config.coso_enabled);
12448        assert!(!config.include_entity_level_controls);
12449        assert_eq!(config.target_maturity_level, "mixed");
12450    }
12451
12452    #[test]
12453    fn test_output_config_defaults() {
12454        let config = OutputConfig::default();
12455        assert!(matches!(config.mode, OutputMode::FlatFile));
12456        assert_eq!(config.formats, vec![FileFormat::Parquet]);
12457        assert!(config.compression.enabled);
12458        assert!(matches!(
12459            config.compression.algorithm,
12460            CompressionAlgorithm::Zstd
12461        ));
12462        assert!(config.include_acdoca);
12463        assert!(!config.include_bseg);
12464        assert!(config.partition_by_period);
12465        assert!(!config.partition_by_company);
12466    }
12467
12468    #[test]
12469    fn test_approval_config_defaults() {
12470        let config = ApprovalConfig::default();
12471        assert!(!config.enabled);
12472        assert_eq!(config.auto_approve_threshold, 1000.0);
12473        assert_eq!(config.rejection_rate, 0.02);
12474        assert_eq!(config.revision_rate, 0.05);
12475        assert_eq!(config.average_approval_delay_hours, 4.0);
12476        assert_eq!(config.thresholds.len(), 4);
12477    }
12478
12479    #[test]
12480    fn test_p2p_flow_config_defaults() {
12481        let config = P2PFlowConfig::default();
12482        assert!(config.enabled);
12483        assert_eq!(config.three_way_match_rate, 0.95);
12484        assert_eq!(config.partial_delivery_rate, 0.15);
12485        assert_eq!(config.average_po_to_gr_days, 14);
12486    }
12487
12488    #[test]
12489    fn test_o2c_flow_config_defaults() {
12490        let config = O2CFlowConfig::default();
12491        assert!(config.enabled);
12492        assert_eq!(config.credit_check_failure_rate, 0.02);
12493        assert_eq!(config.return_rate, 0.03);
12494        assert_eq!(config.bad_debt_rate, 0.01);
12495    }
12496
12497    #[test]
12498    fn test_balance_config_defaults() {
12499        let config = BalanceConfig::default();
12500        assert!(!config.generate_opening_balances);
12501        assert!(config.generate_trial_balances);
12502        assert_eq!(config.target_gross_margin, 0.35);
12503        assert!(config.validate_balance_equation);
12504        assert!(config.reconcile_subledgers);
12505    }
12506
12507    // ==========================================================================
12508    // Partial Config Deserialization Tests
12509    // ==========================================================================
12510
12511    #[test]
12512    fn test_partial_config_with_defaults() {
12513        // Minimal config that should use all defaults
12514        let yaml = r#"
12515            global:
12516              industry: manufacturing
12517              start_date: "2024-01-01"
12518              period_months: 3
12519            companies:
12520              - code: "TEST"
12521                name: "Test Company"
12522                currency: "USD"
12523                country: "US"
12524                annual_transaction_volume: ten_k
12525            chart_of_accounts:
12526              complexity: small
12527            output:
12528              output_directory: "./output"
12529        "#;
12530
12531        let config: GeneratorConfig = serde_yaml::from_str(yaml).expect("Failed to parse");
12532        assert_eq!(config.global.period_months, 3);
12533        assert_eq!(config.companies.len(), 1);
12534        assert!(!config.fraud.enabled); // Default
12535        assert!(!config.internal_controls.enabled); // Default
12536    }
12537
12538    #[test]
12539    fn test_config_with_fraud_enabled() {
12540        let yaml = r#"
12541            global:
12542              industry: retail
12543              start_date: "2024-01-01"
12544              period_months: 12
12545            companies:
12546              - code: "RETAIL"
12547                name: "Retail Co"
12548                currency: "USD"
12549                country: "US"
12550                annual_transaction_volume: hundred_k
12551            chart_of_accounts:
12552              complexity: medium
12553            output:
12554              output_directory: "./output"
12555            fraud:
12556              enabled: true
12557              fraud_rate: 0.05
12558              clustering_enabled: true
12559        "#;
12560
12561        let config: GeneratorConfig = serde_yaml::from_str(yaml).expect("Failed to parse");
12562        assert!(config.fraud.enabled);
12563        assert_eq!(config.fraud.fraud_rate, 0.05);
12564        assert!(config.fraud.clustering_enabled);
12565    }
12566
12567    #[test]
12568    fn test_config_with_multiple_companies() {
12569        let yaml = r#"
12570            global:
12571              industry: manufacturing
12572              start_date: "2024-01-01"
12573              period_months: 6
12574            companies:
12575              - code: "HQ"
12576                name: "Headquarters"
12577                currency: "USD"
12578                country: "US"
12579                annual_transaction_volume: hundred_k
12580                volume_weight: 1.0
12581              - code: "EU"
12582                name: "European Subsidiary"
12583                currency: "EUR"
12584                country: "DE"
12585                annual_transaction_volume: hundred_k
12586                volume_weight: 0.5
12587              - code: "APAC"
12588                name: "Asia Pacific"
12589                currency: "JPY"
12590                country: "JP"
12591                annual_transaction_volume: ten_k
12592                volume_weight: 0.3
12593            chart_of_accounts:
12594              complexity: large
12595            output:
12596              output_directory: "./output"
12597        "#;
12598
12599        let config: GeneratorConfig = serde_yaml::from_str(yaml).expect("Failed to parse");
12600        assert_eq!(config.companies.len(), 3);
12601        assert_eq!(config.companies[0].code, "HQ");
12602        assert_eq!(config.companies[1].currency, "EUR");
12603        assert_eq!(config.companies[2].volume_weight, 0.3);
12604    }
12605
12606    #[test]
12607    fn test_intercompany_config() {
12608        let yaml = r#"
12609            enabled: true
12610            ic_transaction_rate: 0.20
12611            transfer_pricing_method: cost_plus
12612            markup_percent: 0.08
12613            generate_matched_pairs: true
12614            generate_eliminations: true
12615        "#;
12616
12617        let config: IntercompanyConfig = serde_yaml::from_str(yaml).expect("Failed to parse");
12618        assert!(config.enabled);
12619        assert_eq!(config.ic_transaction_rate, 0.20);
12620        assert!(matches!(
12621            config.transfer_pricing_method,
12622            TransferPricingMethod::CostPlus
12623        ));
12624        assert_eq!(config.markup_percent, 0.08);
12625        assert!(config.generate_eliminations);
12626    }
12627
12628    // ==========================================================================
12629    // Company Config Tests
12630    // ==========================================================================
12631
12632    #[test]
12633    fn test_company_config_defaults() {
12634        let yaml = r#"
12635            code: "TEST"
12636            name: "Test Company"
12637            currency: "USD"
12638            country: "US"
12639            annual_transaction_volume: ten_k
12640        "#;
12641
12642        let config: CompanyConfig = serde_yaml::from_str(yaml).expect("Failed to parse");
12643        assert_eq!(config.fiscal_year_variant, "K4"); // Default
12644        assert_eq!(config.volume_weight, 1.0); // Default
12645    }
12646
12647    // ==========================================================================
12648    // Chart of Accounts Config Tests
12649    // ==========================================================================
12650
12651    #[test]
12652    fn test_coa_config_defaults() {
12653        let yaml = r#"
12654            complexity: medium
12655        "#;
12656
12657        let config: ChartOfAccountsConfig = serde_yaml::from_str(yaml).expect("Failed to parse");
12658        assert!(config.industry_specific); // Default true
12659        assert!(config.custom_accounts.is_none());
12660        assert_eq!(config.min_hierarchy_depth, 2); // Default
12661        assert_eq!(config.max_hierarchy_depth, 5); // Default
12662    }
12663
12664    // ==========================================================================
12665    // Accounting Standards Config Tests
12666    // ==========================================================================
12667
12668    #[test]
12669    fn test_accounting_standards_config_defaults() {
12670        let config = AccountingStandardsConfig::default();
12671        assert!(!config.enabled);
12672        assert!(config.framework.is_none());
12673        assert!(!config.revenue_recognition.enabled);
12674        assert!(!config.leases.enabled);
12675        assert!(!config.fair_value.enabled);
12676        assert!(!config.impairment.enabled);
12677        assert!(!config.generate_differences);
12678    }
12679
12680    #[test]
12681    fn test_accounting_standards_config_yaml() {
12682        let yaml = r#"
12683            enabled: true
12684            framework: ifrs
12685            revenue_recognition:
12686              enabled: true
12687              generate_contracts: true
12688              avg_obligations_per_contract: 2.5
12689              variable_consideration_rate: 0.20
12690              over_time_recognition_rate: 0.35
12691              contract_count: 150
12692            leases:
12693              enabled: true
12694              lease_count: 75
12695              finance_lease_percent: 0.25
12696              avg_lease_term_months: 48
12697            generate_differences: true
12698        "#;
12699
12700        let config: AccountingStandardsConfig =
12701            serde_yaml::from_str(yaml).expect("Failed to parse");
12702        assert!(config.enabled);
12703        assert!(matches!(
12704            config.framework,
12705            Some(AccountingFrameworkConfig::Ifrs)
12706        ));
12707        assert!(config.revenue_recognition.enabled);
12708        assert_eq!(config.revenue_recognition.contract_count, 150);
12709        assert_eq!(config.revenue_recognition.avg_obligations_per_contract, 2.5);
12710        assert!(config.leases.enabled);
12711        assert_eq!(config.leases.lease_count, 75);
12712        assert_eq!(config.leases.finance_lease_percent, 0.25);
12713        assert!(config.generate_differences);
12714    }
12715
12716    #[test]
12717    fn test_accounting_framework_serialization() {
12718        let frameworks = [
12719            AccountingFrameworkConfig::UsGaap,
12720            AccountingFrameworkConfig::Ifrs,
12721            AccountingFrameworkConfig::DualReporting,
12722        ];
12723
12724        for framework in frameworks {
12725            let json = serde_json::to_string(&framework).expect("Failed to serialize");
12726            let deserialized: AccountingFrameworkConfig =
12727                serde_json::from_str(&json).expect("Failed to deserialize");
12728            assert!(format!("{:?}", framework) == format!("{:?}", deserialized));
12729        }
12730    }
12731
12732    #[test]
12733    fn test_revenue_recognition_config_defaults() {
12734        let config = RevenueRecognitionConfig::default();
12735        assert!(!config.enabled);
12736        assert!(config.generate_contracts);
12737        assert_eq!(config.avg_obligations_per_contract, 2.0);
12738        assert_eq!(config.variable_consideration_rate, 0.15);
12739        assert_eq!(config.over_time_recognition_rate, 0.30);
12740        assert_eq!(config.contract_count, 100);
12741    }
12742
12743    #[test]
12744    fn test_lease_accounting_config_defaults() {
12745        let config = LeaseAccountingConfig::default();
12746        assert!(!config.enabled);
12747        assert_eq!(config.lease_count, 50);
12748        assert_eq!(config.finance_lease_percent, 0.30);
12749        assert_eq!(config.avg_lease_term_months, 60);
12750        assert!(config.generate_amortization);
12751        assert_eq!(config.real_estate_percent, 0.40);
12752    }
12753
12754    #[test]
12755    fn test_fair_value_config_defaults() {
12756        let config = FairValueConfig::default();
12757        assert!(!config.enabled);
12758        assert_eq!(config.measurement_count, 25);
12759        assert_eq!(config.level1_percent, 0.40);
12760        assert_eq!(config.level2_percent, 0.35);
12761        assert_eq!(config.level3_percent, 0.25);
12762        assert!(!config.include_sensitivity_analysis);
12763    }
12764
12765    #[test]
12766    fn test_impairment_config_defaults() {
12767        let config = ImpairmentConfig::default();
12768        assert!(!config.enabled);
12769        assert_eq!(config.test_count, 15);
12770        assert_eq!(config.impairment_rate, 0.10);
12771        assert!(config.generate_projections);
12772        assert!(!config.include_goodwill);
12773    }
12774
12775    // ==========================================================================
12776    // Audit Standards Config Tests
12777    // ==========================================================================
12778
12779    #[test]
12780    fn test_audit_standards_config_defaults() {
12781        let config = AuditStandardsConfig::default();
12782        assert!(!config.enabled);
12783        assert!(!config.isa_compliance.enabled);
12784        assert!(!config.analytical_procedures.enabled);
12785        assert!(!config.confirmations.enabled);
12786        assert!(!config.opinion.enabled);
12787        assert!(!config.generate_audit_trail);
12788        assert!(!config.sox.enabled);
12789        assert!(!config.pcaob.enabled);
12790    }
12791
12792    #[test]
12793    fn test_audit_standards_config_yaml() {
12794        let yaml = r#"
12795            enabled: true
12796            isa_compliance:
12797              enabled: true
12798              compliance_level: comprehensive
12799              generate_isa_mappings: true
12800              include_pcaob: true
12801              framework: dual
12802            analytical_procedures:
12803              enabled: true
12804              procedures_per_account: 5
12805              variance_probability: 0.25
12806            confirmations:
12807              enabled: true
12808              confirmation_count: 75
12809              positive_response_rate: 0.90
12810              exception_rate: 0.08
12811            opinion:
12812              enabled: true
12813              generate_kam: true
12814              average_kam_count: 4
12815            sox:
12816              enabled: true
12817              generate_302_certifications: true
12818              generate_404_assessments: true
12819              material_weakness_rate: 0.03
12820            pcaob:
12821              enabled: true
12822              is_pcaob_audit: true
12823              include_icfr_opinion: true
12824            generate_audit_trail: true
12825        "#;
12826
12827        let config: AuditStandardsConfig = serde_yaml::from_str(yaml).expect("Failed to parse");
12828        assert!(config.enabled);
12829        assert!(config.isa_compliance.enabled);
12830        assert_eq!(config.isa_compliance.compliance_level, "comprehensive");
12831        assert!(config.isa_compliance.include_pcaob);
12832        assert_eq!(config.isa_compliance.framework, "dual");
12833        assert!(config.analytical_procedures.enabled);
12834        assert_eq!(config.analytical_procedures.procedures_per_account, 5);
12835        assert!(config.confirmations.enabled);
12836        assert_eq!(config.confirmations.confirmation_count, 75);
12837        assert!(config.opinion.enabled);
12838        assert_eq!(config.opinion.average_kam_count, 4);
12839        assert!(config.sox.enabled);
12840        assert!(config.sox.generate_302_certifications);
12841        assert_eq!(config.sox.material_weakness_rate, 0.03);
12842        assert!(config.pcaob.enabled);
12843        assert!(config.pcaob.is_pcaob_audit);
12844        assert!(config.pcaob.include_icfr_opinion);
12845        assert!(config.generate_audit_trail);
12846    }
12847
12848    #[test]
12849    fn test_isa_compliance_config_defaults() {
12850        let config = IsaComplianceConfig::default();
12851        assert!(!config.enabled);
12852        assert_eq!(config.compliance_level, "standard");
12853        assert!(config.generate_isa_mappings);
12854        assert!(config.generate_coverage_summary);
12855        assert!(!config.include_pcaob);
12856        assert_eq!(config.framework, "isa");
12857    }
12858
12859    #[test]
12860    fn test_sox_compliance_config_defaults() {
12861        let config = SoxComplianceConfig::default();
12862        assert!(!config.enabled);
12863        assert!(config.generate_302_certifications);
12864        assert!(config.generate_404_assessments);
12865        assert_eq!(config.materiality_threshold, 10000.0);
12866        assert_eq!(config.material_weakness_rate, 0.02);
12867        assert_eq!(config.significant_deficiency_rate, 0.08);
12868    }
12869
12870    #[test]
12871    fn test_pcaob_config_defaults() {
12872        let config = PcaobConfig::default();
12873        assert!(!config.enabled);
12874        assert!(!config.is_pcaob_audit);
12875        assert!(config.generate_cam);
12876        assert!(!config.include_icfr_opinion);
12877        assert!(!config.generate_standard_mappings);
12878    }
12879
12880    #[test]
12881    fn test_config_with_standards_enabled() {
12882        let yaml = r#"
12883            global:
12884              industry: financial_services
12885              start_date: "2024-01-01"
12886              period_months: 12
12887            companies:
12888              - code: "BANK"
12889                name: "Test Bank"
12890                currency: "USD"
12891                country: "US"
12892                annual_transaction_volume: hundred_k
12893            chart_of_accounts:
12894              complexity: large
12895            output:
12896              output_directory: "./output"
12897            accounting_standards:
12898              enabled: true
12899              framework: us_gaap
12900              revenue_recognition:
12901                enabled: true
12902              leases:
12903                enabled: true
12904            audit_standards:
12905              enabled: true
12906              isa_compliance:
12907                enabled: true
12908              sox:
12909                enabled: true
12910        "#;
12911
12912        let config: GeneratorConfig = serde_yaml::from_str(yaml).expect("Failed to parse");
12913        assert!(config.accounting_standards.enabled);
12914        assert!(matches!(
12915            config.accounting_standards.framework,
12916            Some(AccountingFrameworkConfig::UsGaap)
12917        ));
12918        assert!(config.accounting_standards.revenue_recognition.enabled);
12919        assert!(config.accounting_standards.leases.enabled);
12920        assert!(config.audit_standards.enabled);
12921        assert!(config.audit_standards.isa_compliance.enabled);
12922        assert!(config.audit_standards.sox.enabled);
12923    }
12924
12925    // ==========================================================================
12926    // Industry-Specific Config Tests
12927    // ==========================================================================
12928
12929    #[test]
12930    fn test_industry_specific_config_defaults() {
12931        let config = IndustrySpecificConfig::default();
12932        assert!(!config.enabled);
12933        assert!(!config.manufacturing.enabled);
12934        assert!(!config.retail.enabled);
12935        assert!(!config.healthcare.enabled);
12936        assert!(!config.technology.enabled);
12937        assert!(!config.financial_services.enabled);
12938        assert!(!config.professional_services.enabled);
12939    }
12940
12941    #[test]
12942    fn test_manufacturing_config_defaults() {
12943        let config = ManufacturingConfig::default();
12944        assert!(!config.enabled);
12945        assert_eq!(config.bom_depth, 4);
12946        assert!(!config.just_in_time);
12947        assert_eq!(config.supplier_tiers, 2);
12948        assert_eq!(config.target_yield_rate, 0.97);
12949        assert_eq!(config.scrap_alert_threshold, 0.03);
12950    }
12951
12952    #[test]
12953    fn test_retail_config_defaults() {
12954        let config = RetailConfig::default();
12955        assert!(!config.enabled);
12956        assert_eq!(config.avg_daily_transactions, 500);
12957        assert!(config.loss_prevention);
12958        assert_eq!(config.shrinkage_rate, 0.015);
12959    }
12960
12961    #[test]
12962    fn test_healthcare_config_defaults() {
12963        let config = HealthcareConfig::default();
12964        assert!(!config.enabled);
12965        assert_eq!(config.facility_type, "hospital");
12966        assert_eq!(config.avg_daily_encounters, 150);
12967        assert!(config.compliance.hipaa);
12968        assert!(config.compliance.stark_law);
12969        assert!(config.coding_systems.icd10);
12970        assert!(config.coding_systems.cpt);
12971    }
12972
12973    #[test]
12974    fn test_technology_config_defaults() {
12975        let config = TechnologyConfig::default();
12976        assert!(!config.enabled);
12977        assert_eq!(config.revenue_model, "saas");
12978        assert_eq!(config.subscription_revenue_pct, 0.60);
12979        assert!(config.rd_capitalization.enabled);
12980    }
12981
12982    #[test]
12983    fn test_config_with_industry_specific() {
12984        let yaml = r#"
12985            global:
12986              industry: healthcare
12987              start_date: "2024-01-01"
12988              period_months: 12
12989            companies:
12990              - code: "HOSP"
12991                name: "Test Hospital"
12992                currency: "USD"
12993                country: "US"
12994                annual_transaction_volume: hundred_k
12995            chart_of_accounts:
12996              complexity: medium
12997            output:
12998              output_directory: "./output"
12999            industry_specific:
13000              enabled: true
13001              healthcare:
13002                enabled: true
13003                facility_type: hospital
13004                payer_mix:
13005                  medicare: 0.45
13006                  medicaid: 0.15
13007                  commercial: 0.35
13008                  self_pay: 0.05
13009                coding_systems:
13010                  icd10: true
13011                  cpt: true
13012                  drg: true
13013                compliance:
13014                  hipaa: true
13015                  stark_law: true
13016                anomaly_rates:
13017                  upcoding: 0.03
13018                  unbundling: 0.02
13019        "#;
13020
13021        let config: GeneratorConfig = serde_yaml::from_str(yaml).expect("Failed to parse");
13022        assert!(config.industry_specific.enabled);
13023        assert!(config.industry_specific.healthcare.enabled);
13024        assert_eq!(
13025            config.industry_specific.healthcare.facility_type,
13026            "hospital"
13027        );
13028        assert_eq!(config.industry_specific.healthcare.payer_mix.medicare, 0.45);
13029        assert_eq!(config.industry_specific.healthcare.payer_mix.self_pay, 0.05);
13030        assert!(config.industry_specific.healthcare.coding_systems.icd10);
13031        assert!(config.industry_specific.healthcare.compliance.hipaa);
13032        assert_eq!(
13033            config.industry_specific.healthcare.anomaly_rates.upcoding,
13034            0.03
13035        );
13036    }
13037
13038    #[test]
13039    fn test_config_with_manufacturing_specific() {
13040        let yaml = r#"
13041            global:
13042              industry: manufacturing
13043              start_date: "2024-01-01"
13044              period_months: 12
13045            companies:
13046              - code: "MFG"
13047                name: "Test Manufacturing"
13048                currency: "USD"
13049                country: "US"
13050                annual_transaction_volume: hundred_k
13051            chart_of_accounts:
13052              complexity: medium
13053            output:
13054              output_directory: "./output"
13055            industry_specific:
13056              enabled: true
13057              manufacturing:
13058                enabled: true
13059                bom_depth: 5
13060                just_in_time: true
13061                supplier_tiers: 3
13062                target_yield_rate: 0.98
13063                anomaly_rates:
13064                  yield_manipulation: 0.02
13065                  phantom_production: 0.01
13066        "#;
13067
13068        let config: GeneratorConfig = serde_yaml::from_str(yaml).expect("Failed to parse");
13069        assert!(config.industry_specific.enabled);
13070        assert!(config.industry_specific.manufacturing.enabled);
13071        assert_eq!(config.industry_specific.manufacturing.bom_depth, 5);
13072        assert!(config.industry_specific.manufacturing.just_in_time);
13073        assert_eq!(config.industry_specific.manufacturing.supplier_tiers, 3);
13074        assert_eq!(
13075            config.industry_specific.manufacturing.target_yield_rate,
13076            0.98
13077        );
13078        assert_eq!(
13079            config
13080                .industry_specific
13081                .manufacturing
13082                .anomaly_rates
13083                .yield_manipulation,
13084            0.02
13085        );
13086    }
13087
13088    // ==========================================================================
13089    // Tax Configuration Tests
13090    // ==========================================================================
13091
13092    #[test]
13093    fn test_tax_config_defaults() {
13094        let tax = TaxConfig::default();
13095        assert!(!tax.enabled);
13096        assert!(tax.jurisdictions.countries.is_empty());
13097        assert!(!tax.jurisdictions.include_subnational);
13098        assert!(!tax.vat_gst.enabled);
13099        assert!(tax.vat_gst.standard_rates.is_empty());
13100        assert!(tax.vat_gst.reduced_rates.is_empty());
13101        assert!(tax.vat_gst.exempt_categories.is_empty());
13102        assert!(tax.vat_gst.reverse_charge);
13103        assert!(!tax.sales_tax.enabled);
13104        assert!(tax.sales_tax.nexus_states.is_empty());
13105        assert!(!tax.withholding.enabled);
13106        assert!(tax.withholding.treaty_network);
13107        assert_eq!(tax.withholding.default_rate, 0.30);
13108        assert_eq!(tax.withholding.treaty_reduced_rate, 0.15);
13109        assert!(tax.provisions.enabled);
13110        assert_eq!(tax.provisions.statutory_rate, 0.21);
13111        assert!(tax.provisions.uncertain_positions);
13112        assert!(!tax.payroll_tax.enabled);
13113        assert_eq!(tax.anomaly_rate, 0.03);
13114    }
13115
13116    #[test]
13117    fn test_tax_config_from_yaml() {
13118        let yaml = r#"
13119            global:
13120              seed: 42
13121              start_date: "2024-01-01"
13122              period_months: 12
13123              industry: retail
13124            companies:
13125              - code: C001
13126                name: Test Corp
13127                currency: USD
13128                country: US
13129                annual_transaction_volume: ten_k
13130            chart_of_accounts:
13131              complexity: small
13132            output:
13133              output_directory: ./output
13134            tax:
13135              enabled: true
13136              anomaly_rate: 0.05
13137              jurisdictions:
13138                countries: ["US", "DE", "GB"]
13139                include_subnational: true
13140              vat_gst:
13141                enabled: true
13142                standard_rates:
13143                  DE: 0.19
13144                  GB: 0.20
13145                reduced_rates:
13146                  DE: 0.07
13147                  GB: 0.05
13148                exempt_categories:
13149                  - financial_services
13150                  - healthcare
13151                reverse_charge: false
13152              sales_tax:
13153                enabled: true
13154                nexus_states: ["CA", "NY", "TX"]
13155              withholding:
13156                enabled: true
13157                treaty_network: false
13158                default_rate: 0.25
13159                treaty_reduced_rate: 0.10
13160              provisions:
13161                enabled: false
13162                statutory_rate: 0.28
13163                uncertain_positions: false
13164              payroll_tax:
13165                enabled: true
13166        "#;
13167
13168        let config: GeneratorConfig = serde_yaml::from_str(yaml).expect("Failed to parse");
13169        assert!(config.tax.enabled);
13170        assert_eq!(config.tax.anomaly_rate, 0.05);
13171
13172        // Jurisdictions
13173        assert_eq!(config.tax.jurisdictions.countries.len(), 3);
13174        assert!(config
13175            .tax
13176            .jurisdictions
13177            .countries
13178            .contains(&"DE".to_string()));
13179        assert!(config.tax.jurisdictions.include_subnational);
13180
13181        // VAT/GST
13182        assert!(config.tax.vat_gst.enabled);
13183        assert_eq!(config.tax.vat_gst.standard_rates.get("DE"), Some(&0.19));
13184        assert_eq!(config.tax.vat_gst.standard_rates.get("GB"), Some(&0.20));
13185        assert_eq!(config.tax.vat_gst.reduced_rates.get("DE"), Some(&0.07));
13186        assert_eq!(config.tax.vat_gst.exempt_categories.len(), 2);
13187        assert!(!config.tax.vat_gst.reverse_charge);
13188
13189        // Sales tax
13190        assert!(config.tax.sales_tax.enabled);
13191        assert_eq!(config.tax.sales_tax.nexus_states.len(), 3);
13192        assert!(config
13193            .tax
13194            .sales_tax
13195            .nexus_states
13196            .contains(&"CA".to_string()));
13197
13198        // Withholding
13199        assert!(config.tax.withholding.enabled);
13200        assert!(!config.tax.withholding.treaty_network);
13201        assert_eq!(config.tax.withholding.default_rate, 0.25);
13202        assert_eq!(config.tax.withholding.treaty_reduced_rate, 0.10);
13203
13204        // Provisions
13205        assert!(!config.tax.provisions.enabled);
13206        assert_eq!(config.tax.provisions.statutory_rate, 0.28);
13207        assert!(!config.tax.provisions.uncertain_positions);
13208
13209        // Payroll tax
13210        assert!(config.tax.payroll_tax.enabled);
13211    }
13212
13213    #[test]
13214    fn test_generator_config_with_tax_default() {
13215        let yaml = r#"
13216            global:
13217              seed: 42
13218              start_date: "2024-01-01"
13219              period_months: 12
13220              industry: retail
13221            companies:
13222              - code: C001
13223                name: Test Corp
13224                currency: USD
13225                country: US
13226                annual_transaction_volume: ten_k
13227            chart_of_accounts:
13228              complexity: small
13229            output:
13230              output_directory: ./output
13231        "#;
13232
13233        let config: GeneratorConfig =
13234            serde_yaml::from_str(yaml).expect("Failed to parse config without tax section");
13235        // Tax should be present with defaults when not specified in YAML
13236        assert!(!config.tax.enabled);
13237        assert!(config.tax.jurisdictions.countries.is_empty());
13238        assert_eq!(config.tax.anomaly_rate, 0.03);
13239        assert!(config.tax.provisions.enabled); // provisions default to enabled=true
13240        assert_eq!(config.tax.provisions.statutory_rate, 0.21);
13241    }
13242}