datasynth-generators 2.4.0

50+ data generators covering GL, P2P, O2C, S2C, HR, manufacturing, audit, tax, treasury, and ESG
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
//! Trial balance generator.
//!
//! Generates trial balances at period end from running balance snapshots,
//! with support for:
//! - Unadjusted, adjusted, and post-closing trial balances
//! - Category summaries and subtotals
//! - Comparative trial balances across periods
//! - Consolidated trial balances across companies

use chrono::NaiveDate;
use rust_decimal::Decimal;
use rust_decimal_macros::dec;
use std::collections::HashMap;
use tracing::debug;

use datasynth_core::models::balance::{
    AccountBalance, AccountCategory, AccountType, BalanceSnapshot, CategorySummary,
    ComparativeTrialBalance, TrialBalance, TrialBalanceLine, TrialBalanceStatus, TrialBalanceType,
};
use datasynth_core::models::ChartOfAccounts;
use datasynth_core::FrameworkAccounts;

use super::RunningBalanceTracker;

/// Configuration for trial balance generation.
#[derive(Debug, Clone)]
pub struct TrialBalanceConfig {
    /// Include zero balance accounts.
    pub include_zero_balances: bool,
    /// Group accounts by category.
    pub group_by_category: bool,
    /// Generate category subtotals.
    pub generate_subtotals: bool,
    /// Sort accounts by code.
    pub sort_by_account_code: bool,
    /// Trial balance type to generate.
    pub trial_balance_type: TrialBalanceType,
}

impl Default for TrialBalanceConfig {
    fn default() -> Self {
        Self {
            include_zero_balances: false,
            group_by_category: true,
            generate_subtotals: true,
            sort_by_account_code: true,
            trial_balance_type: TrialBalanceType::Unadjusted,
        }
    }
}

/// Generator for trial balance reports.
pub struct TrialBalanceGenerator {
    config: TrialBalanceConfig,
    /// Account category mappings.
    category_mappings: HashMap<String, AccountCategory>,
    /// Account descriptions.
    account_descriptions: HashMap<String, String>,
    /// Framework-aware account classification.
    framework_accounts: FrameworkAccounts,
}

impl TrialBalanceGenerator {
    /// Creates a new trial balance generator for a specific accounting framework.
    pub fn new_with_framework(config: TrialBalanceConfig, framework: &str) -> Self {
        Self {
            config,
            category_mappings: HashMap::new(),
            account_descriptions: HashMap::new(),
            framework_accounts: FrameworkAccounts::for_framework(framework),
        }
    }

    /// Creates a new trial balance generator (defaults to US GAAP).
    pub fn new(config: TrialBalanceConfig) -> Self {
        Self::new_with_framework(config, "us_gaap")
    }

    /// Creates a generator with default configuration (US GAAP).
    pub fn with_defaults() -> Self {
        Self::new(TrialBalanceConfig::default())
    }

    /// Registers category mappings from chart of accounts.
    pub fn register_from_chart(&mut self, chart: &ChartOfAccounts) {
        for account in &chart.accounts {
            self.account_descriptions.insert(
                account.account_code().to_string(),
                account.description().to_string(),
            );

            // Determine category from account code prefix
            let category = self.determine_category(account.account_code());
            self.category_mappings
                .insert(account.account_code().to_string(), category);
        }
    }

    /// Registers a custom category mapping.
    pub fn register_category(&mut self, account_code: &str, category: AccountCategory) {
        self.category_mappings
            .insert(account_code.to_string(), category);
    }

    /// Generates a trial balance from a balance snapshot.
    pub fn generate_from_snapshot(
        &self,
        snapshot: &BalanceSnapshot,
        fiscal_year: i32,
        fiscal_period: u32,
    ) -> TrialBalance {
        debug!(
            company_code = %snapshot.company_code,
            fiscal_year,
            fiscal_period,
            balance_count = snapshot.balances.len(),
            "Generating trial balance from snapshot"
        );

        let mut lines = Vec::new();
        let mut total_debits = Decimal::ZERO;
        let mut total_credits = Decimal::ZERO;

        // Convert balances to trial balance lines
        for (account_code, balance) in &snapshot.balances {
            if !self.config.include_zero_balances && balance.closing_balance == Decimal::ZERO {
                continue;
            }

            let (debit, credit) = self.split_balance(balance);
            total_debits += debit;
            total_credits += credit;

            let category = self.determine_category(account_code);
            let description = self
                .account_descriptions
                .get(account_code)
                .cloned()
                .unwrap_or_else(|| format!("Account {account_code}"));

            lines.push(TrialBalanceLine {
                account_code: account_code.clone(),
                account_description: description,
                category,
                account_type: balance.account_type,
                debit_balance: debit,
                credit_balance: credit,
                opening_balance: balance.opening_balance,
                period_debits: balance.period_debits,
                period_credits: balance.period_credits,
                closing_balance: balance.closing_balance,
                cost_center: None,
                profit_center: None,
            });
        }

        // Sort lines
        if self.config.sort_by_account_code {
            lines.sort_by(|a, b| a.account_code.cmp(&b.account_code));
        }

        // Calculate category summaries
        let category_summary = if self.config.group_by_category {
            self.calculate_category_summary(&lines)
        } else {
            HashMap::new()
        };

        let out_of_balance = total_debits - total_credits;

        let mut tb = TrialBalance {
            trial_balance_id: format!(
                "TB-{}-{}-{:02}",
                snapshot.company_code, fiscal_year, fiscal_period
            ),
            company_code: snapshot.company_code.clone(),
            company_name: None,
            as_of_date: snapshot.as_of_date,
            fiscal_year,
            fiscal_period,
            currency: snapshot.currency.clone(),
            balance_type: self.config.trial_balance_type,
            lines,
            total_debits,
            total_credits,
            is_balanced: out_of_balance.abs() < dec!(0.01),
            out_of_balance,
            is_equation_valid: false,           // Will be calculated below
            equation_difference: Decimal::ZERO, // Will be calculated below
            category_summary,
            created_at: snapshot
                .as_of_date
                .and_hms_opt(23, 59, 59)
                .unwrap_or_default(),
            created_by: "TrialBalanceGenerator".to_string(),
            approved_by: None,
            approved_at: None,
            status: TrialBalanceStatus::Draft,
        };

        // Calculate and set accounting equation validity
        let (is_valid, _assets, _liabilities, _equity, diff) = tb.validate_accounting_equation();
        tb.is_equation_valid = is_valid;
        tb.equation_difference = diff;

        tb
    }

    /// Generates a trial balance from the balance tracker.
    pub fn generate_from_tracker(
        &self,
        tracker: &RunningBalanceTracker,
        company_code: &str,
        as_of_date: NaiveDate,
        fiscal_year: i32,
        fiscal_period: u32,
    ) -> Option<TrialBalance> {
        tracker
            .get_snapshot(company_code, as_of_date)
            .map(|snapshot| self.generate_from_snapshot(&snapshot, fiscal_year, fiscal_period))
    }

    /// Generates trial balances for all companies in the tracker.
    pub fn generate_all_from_tracker(
        &self,
        tracker: &RunningBalanceTracker,
        as_of_date: NaiveDate,
        fiscal_year: i32,
        fiscal_period: u32,
    ) -> Vec<TrialBalance> {
        tracker
            .get_all_snapshots(as_of_date)
            .iter()
            .map(|snapshot| self.generate_from_snapshot(snapshot, fiscal_year, fiscal_period))
            .collect()
    }

    /// Generates a comparative trial balance across multiple periods.
    pub fn generate_comparative(
        &self,
        snapshots: &[(NaiveDate, BalanceSnapshot)],
        fiscal_year: i32,
    ) -> ComparativeTrialBalance {
        use datasynth_core::models::balance::ComparativeTrialBalanceLine;

        // Generate trial balances for each period
        let trial_balances: Vec<TrialBalance> = snapshots
            .iter()
            .enumerate()
            .map(|(i, (date, snapshot))| {
                let mut tb = self.generate_from_snapshot(snapshot, fiscal_year, (i + 1) as u32);
                tb.as_of_date = *date;
                tb
            })
            .collect();

        // Build periods list
        let periods: Vec<(i32, u32)> = trial_balances
            .iter()
            .map(|tb| (tb.fiscal_year, tb.fiscal_period))
            .collect();

        // Build comparative lines
        let mut lines_map: HashMap<String, ComparativeTrialBalanceLine> = HashMap::new();

        for tb in &trial_balances {
            for line in &tb.lines {
                let entry = lines_map
                    .entry(line.account_code.clone())
                    .or_insert_with(|| ComparativeTrialBalanceLine {
                        account_code: line.account_code.clone(),
                        account_description: line.account_description.clone(),
                        category: line.category,
                        period_balances: HashMap::new(),
                        period_changes: HashMap::new(),
                    });

                entry
                    .period_balances
                    .insert((tb.fiscal_year, tb.fiscal_period), line.closing_balance);
            }
        }

        // Calculate period-over-period changes
        for line in lines_map.values_mut() {
            let mut sorted_periods: Vec<_> = line.period_balances.keys().cloned().collect();
            sorted_periods.sort();

            for i in 1..sorted_periods.len() {
                let prev_period = sorted_periods[i - 1];
                let curr_period = sorted_periods[i];

                if let (Some(&prev_balance), Some(&curr_balance)) = (
                    line.period_balances.get(&prev_period),
                    line.period_balances.get(&curr_period),
                ) {
                    line.period_changes
                        .insert(curr_period, curr_balance - prev_balance);
                }
            }
        }

        let lines: Vec<ComparativeTrialBalanceLine> = lines_map.into_values().collect();

        let company_code = snapshots
            .first()
            .map(|(_, s)| s.company_code.clone())
            .unwrap_or_default();

        let currency = snapshots
            .first()
            .map(|(_, s)| s.currency.clone())
            .unwrap_or_else(|| "USD".to_string());

        let created_at = snapshots
            .last()
            .map(|(date, _)| date.and_hms_opt(23, 59, 59).unwrap_or_default())
            .unwrap_or_default();

        ComparativeTrialBalance {
            company_code,
            currency,
            periods,
            lines,
            created_at,
        }
    }

    /// Generates a consolidated trial balance across companies.
    pub fn generate_consolidated(
        &self,
        trial_balances: &[TrialBalance],
        consolidated_company_code: &str,
    ) -> TrialBalance {
        let mut consolidated_balances: HashMap<String, TrialBalanceLine> = HashMap::new();

        for tb in trial_balances {
            for line in &tb.lines {
                let entry = consolidated_balances
                    .entry(line.account_code.clone())
                    .or_insert_with(|| TrialBalanceLine {
                        account_code: line.account_code.clone(),
                        account_description: line.account_description.clone(),
                        category: line.category,
                        account_type: line.account_type,
                        debit_balance: Decimal::ZERO,
                        credit_balance: Decimal::ZERO,
                        opening_balance: Decimal::ZERO,
                        period_debits: Decimal::ZERO,
                        period_credits: Decimal::ZERO,
                        closing_balance: Decimal::ZERO,
                        cost_center: None,
                        profit_center: None,
                    });

                entry.debit_balance += line.debit_balance;
                entry.credit_balance += line.credit_balance;
                entry.opening_balance += line.opening_balance;
                entry.period_debits += line.period_debits;
                entry.period_credits += line.period_credits;
                entry.closing_balance += line.closing_balance;
            }
        }

        let mut lines: Vec<TrialBalanceLine> = consolidated_balances.into_values().collect();
        if self.config.sort_by_account_code {
            lines.sort_by(|a, b| a.account_code.cmp(&b.account_code));
        }

        let total_debits: Decimal = lines.iter().map(|l| l.debit_balance).sum();
        let total_credits: Decimal = lines.iter().map(|l| l.credit_balance).sum();

        let category_summary = if self.config.group_by_category {
            self.calculate_category_summary(&lines)
        } else {
            HashMap::new()
        };

        let as_of_date = trial_balances
            .first()
            .map(|tb| tb.as_of_date)
            .unwrap_or_else(|| chrono::Local::now().date_naive());

        let fiscal_year = trial_balances.first().map(|tb| tb.fiscal_year).unwrap_or(0);
        let fiscal_period = trial_balances
            .first()
            .map(|tb| tb.fiscal_period)
            .unwrap_or(0);

        let currency = trial_balances
            .first()
            .map(|tb| tb.currency.clone())
            .unwrap_or_else(|| "USD".to_string());

        let out_of_balance = total_debits - total_credits;

        let mut tb = TrialBalance {
            trial_balance_id: format!(
                "TB-CONS-{consolidated_company_code}-{fiscal_year}-{fiscal_period:02}"
            ),
            company_code: consolidated_company_code.to_string(),
            company_name: None,
            as_of_date,
            fiscal_year,
            fiscal_period,
            currency,
            balance_type: TrialBalanceType::Consolidated,
            lines,
            total_debits,
            total_credits,
            is_balanced: out_of_balance.abs() < dec!(0.01),
            out_of_balance,
            is_equation_valid: false,           // Will be calculated below
            equation_difference: Decimal::ZERO, // Will be calculated below
            category_summary,
            created_at: as_of_date.and_hms_opt(23, 59, 59).unwrap_or_default(),
            created_by: format!(
                "TrialBalanceGenerator (Consolidated from {} companies)",
                trial_balances.len()
            ),
            approved_by: None,
            approved_at: None,
            status: TrialBalanceStatus::Draft,
        };

        // Calculate and set accounting equation validity
        let (is_valid, _assets, _liabilities, _equity, diff) = tb.validate_accounting_equation();
        tb.is_equation_valid = is_valid;
        tb.equation_difference = diff;

        tb
    }

    /// Splits a balance into debit and credit components.
    fn split_balance(&self, balance: &AccountBalance) -> (Decimal, Decimal) {
        let closing = balance.closing_balance;

        // Determine natural balance side based on account type
        match balance.account_type {
            AccountType::Asset | AccountType::Expense => {
                if closing >= Decimal::ZERO {
                    (closing, Decimal::ZERO)
                } else {
                    (Decimal::ZERO, closing.abs())
                }
            }
            AccountType::ContraAsset | AccountType::ContraLiability | AccountType::ContraEquity => {
                // Contra accounts have opposite natural balance
                if closing >= Decimal::ZERO {
                    (Decimal::ZERO, closing)
                } else {
                    (closing.abs(), Decimal::ZERO)
                }
            }
            AccountType::Liability | AccountType::Equity | AccountType::Revenue => {
                if closing >= Decimal::ZERO {
                    (Decimal::ZERO, closing)
                } else {
                    (closing.abs(), Decimal::ZERO)
                }
            }
        }
    }

    /// Determines account category from code prefix.
    ///
    /// Checks explicitly registered mappings first, then falls back to the
    /// framework-aware classifier from [`FrameworkAccounts`].
    fn determine_category(&self, account_code: &str) -> AccountCategory {
        // Check registered mappings first
        if let Some(category) = self.category_mappings.get(account_code) {
            return *category;
        }

        // Use framework-aware classification
        self.framework_accounts
            .classify_trial_balance_category(account_code)
    }

    /// Calculates category summaries from lines.
    fn calculate_category_summary(
        &self,
        lines: &[TrialBalanceLine],
    ) -> HashMap<AccountCategory, CategorySummary> {
        let mut summaries: HashMap<AccountCategory, CategorySummary> = HashMap::new();

        for line in lines {
            let summary = summaries
                .entry(line.category)
                .or_insert_with(|| CategorySummary::new(line.category));

            summary.add_balance(line.debit_balance, line.credit_balance);
        }

        summaries
    }

    /// Finalizes a trial balance (changes status to Final).
    pub fn finalize(&self, mut trial_balance: TrialBalance) -> TrialBalance {
        trial_balance.status = TrialBalanceStatus::Final;
        trial_balance
    }

    /// Approves a trial balance.
    pub fn approve(&self, mut trial_balance: TrialBalance, approver: &str) -> TrialBalance {
        trial_balance.status = TrialBalanceStatus::Approved;
        trial_balance.approved_by = Some(approver.to_string());
        trial_balance.approved_at = Some(
            trial_balance
                .as_of_date
                .succ_opt()
                .unwrap_or(trial_balance.as_of_date)
                .and_hms_opt(9, 0, 0)
                .unwrap_or_default(),
        );
        trial_balance
    }
}

/// Builder for trial balance generation with fluent API.
pub struct TrialBalanceBuilder {
    generator: TrialBalanceGenerator,
    snapshots: Vec<(String, BalanceSnapshot)>,
    fiscal_year: i32,
    fiscal_period: u32,
}

impl TrialBalanceBuilder {
    /// Creates a new builder.
    pub fn new(fiscal_year: i32, fiscal_period: u32) -> Self {
        Self {
            generator: TrialBalanceGenerator::with_defaults(),
            snapshots: Vec::new(),
            fiscal_year,
            fiscal_period,
        }
    }

    /// Adds a balance snapshot.
    pub fn add_snapshot(mut self, company_code: &str, snapshot: BalanceSnapshot) -> Self {
        self.snapshots.push((company_code.to_string(), snapshot));
        self
    }

    /// Sets configuration.
    pub fn with_config(mut self, config: TrialBalanceConfig) -> Self {
        self.generator = TrialBalanceGenerator::new(config);
        self
    }

    /// Builds individual trial balances.
    pub fn build(self) -> Vec<TrialBalance> {
        self.snapshots
            .iter()
            .map(|(_, snapshot)| {
                self.generator.generate_from_snapshot(
                    snapshot,
                    self.fiscal_year,
                    self.fiscal_period,
                )
            })
            .collect()
    }

    /// Builds a consolidated trial balance.
    pub fn build_consolidated(self, consolidated_code: &str) -> TrialBalance {
        let individual = self
            .snapshots
            .iter()
            .map(|(_, snapshot)| {
                self.generator.generate_from_snapshot(
                    snapshot,
                    self.fiscal_year,
                    self.fiscal_period,
                )
            })
            .collect::<Vec<_>>();

        self.generator
            .generate_consolidated(&individual, consolidated_code)
    }
}

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

    fn create_test_balance(
        company: &str,
        account: &str,
        acct_type: AccountType,
        opening: Decimal,
    ) -> AccountBalance {
        let mut bal = AccountBalance::new(
            company.to_string(),
            account.to_string(),
            acct_type,
            "USD".to_string(),
            2024,
            1,
        );
        bal.opening_balance = opening;
        bal.closing_balance = opening;
        bal
    }

    fn create_test_snapshot() -> BalanceSnapshot {
        let mut snapshot = BalanceSnapshot::new(
            "SNAP-TEST-2024-01".to_string(),
            "TEST".to_string(),
            NaiveDate::from_ymd_opt(2024, 1, 31).unwrap(),
            2024,
            1,
            "USD".to_string(),
        );

        // Add assets
        snapshot.balances.insert(
            "1100".to_string(),
            create_test_balance("TEST", "1100", AccountType::Asset, dec!(10000)),
        );

        // Add liabilities
        snapshot.balances.insert(
            "2100".to_string(),
            create_test_balance("TEST", "2100", AccountType::Liability, dec!(5000)),
        );

        // Add equity
        snapshot.balances.insert(
            "3100".to_string(),
            create_test_balance("TEST", "3100", AccountType::Equity, dec!(5000)),
        );

        snapshot.recalculate_totals();
        snapshot
    }

    #[test]
    fn test_generate_trial_balance() {
        let generator = TrialBalanceGenerator::with_defaults();
        let snapshot = create_test_snapshot();

        let tb = generator.generate_from_snapshot(&snapshot, 2024, 1);

        assert!(tb.is_balanced);
        assert_eq!(tb.lines.len(), 3);
        assert_eq!(tb.total_debits, dec!(10000));
        assert_eq!(tb.total_credits, dec!(10000));
    }

    #[test]
    fn test_category_summaries() {
        let generator = TrialBalanceGenerator::with_defaults();
        let snapshot = create_test_snapshot();

        let tb = generator.generate_from_snapshot(&snapshot, 2024, 1);

        assert!(!tb.category_summary.is_empty());
    }

    #[test]
    fn test_consolidated_trial_balance() {
        let generator = TrialBalanceGenerator::with_defaults();

        let snapshot1 = create_test_snapshot();
        let mut snapshot2 = BalanceSnapshot::new(
            "SNAP-TEST2-2024-01".to_string(),
            "TEST2".to_string(),
            snapshot1.as_of_date,
            2024,
            1,
            "USD".to_string(),
        );

        // Copy and double the balances
        for (code, balance) in &snapshot1.balances {
            let mut new_bal = balance.clone();
            new_bal.company_code = "TEST2".to_string();
            new_bal.closing_balance *= dec!(2);
            new_bal.opening_balance *= dec!(2);
            snapshot2.balances.insert(code.clone(), new_bal);
        }
        snapshot2.recalculate_totals();

        let tb1 = generator.generate_from_snapshot(&snapshot1, 2024, 1);
        let tb2 = generator.generate_from_snapshot(&snapshot2, 2024, 1);

        let consolidated = generator.generate_consolidated(&[tb1, tb2], "CONSOL");

        assert_eq!(consolidated.company_code, "CONSOL");
        assert!(consolidated.is_balanced);
    }

    #[test]
    fn test_builder_pattern() {
        let snapshot = create_test_snapshot();

        let trial_balances = TrialBalanceBuilder::new(2024, 1)
            .add_snapshot("TEST", snapshot)
            .build();

        assert_eq!(trial_balances.len(), 1);
        assert!(trial_balances[0].is_balanced);
    }
}