mudra-cli 0.1.0

A robust, high-performance currency converter with caching and CLI interface
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
//! Command-line interface for the currency converter

use clap::{Parser, Subcommand};
use colored::*;
use indicatif::{ProgressBar, ProgressStyle};
use mudra_cli::{ConversionRequest, ConversionType, CurrencyConverter, CurrencyError, Result};
use std::time::Duration;

/// Currency Converter CLI
#[derive(Parser)]
#[command(
    name = "mudra",
    about = "A robust currency converter using real-time exchange rates",
    version = "0.1.0",
    author = "Your Name"
)]
pub struct Cli {
    #[command(subcommand)]
    pub command: Commands,

    /// Verbose output
    #[arg(short, long, global = true)]
    pub verbose: bool,

    /// Disable colored output
    #[arg(long, global = true)]
    pub no_color: bool,
}

#[derive(Subcommand)]
pub enum Commands {
    /// Convert currency amounts
    Convert {
        /// Amount to convert
        amount: f64,

        /// Source currency code (e.g., USD, EUR, GBP)
        from: String,

        /// Target currency code (e.g., USD, EUR, GBP)
        to: String,

        /// Round result to specified decimal places
        #[arg(short, long, default_value = "2")]
        precision: u32,

        /// Historical date for conversion (YYYY-MM-DD format)
        #[arg(long)]
        date: Option<String>,
    },

    /// List supported currencies
    List {
        /// Show extended information
        #[arg(short, long)]
        extended: bool,

        /// Filter currencies by pattern
        #[arg(short, long)]
        filter: Option<String>,
    },

    /// Show current exchange rates for a base currency
    Rates {
        /// Base currency code
        base: String,

        /// Show only rates for these currencies (comma-separated)
        #[arg(short, long)]
        currencies: Option<String>,

        /// Number of currencies to show (default: all)
        #[arg(short, long)]
        limit: Option<usize>,

        /// Historical date for rates (YYYY-MM-DD format)
        #[arg(long)]
        date: Option<String>,
    },

    /// Compare amounts across multiple currencies
    Compare {
        /// Amount to compare
        amount: f64,

        /// Base currency code
        from: String,

        /// Target currencies (comma-separated)
        to: String,

        /// Historical date for comparison (YYYY-MM-DD format)
        #[arg(long)]
        date: Option<String>,
    },

    /// Cache management commands
    Cache {
        #[command(subcommand)]
        action: CacheAction,
    },

    /// Interactive mode
    Interactive,
}

#[derive(Subcommand)]
pub enum CacheAction {
    /// Show cache statistics
    Stats,

    /// Clear all cached data
    Clear,

    /// Clean up expired cache entries
    Cleanup,
}

/// CLI handler and formatter
pub struct CliHandler {
    converter: CurrencyConverter,
    verbose: bool,
    use_color: bool,
}

impl CliHandler {
    /// Create a new CLI handler
    pub fn new(converter: CurrencyConverter, verbose: bool, use_color: bool) -> Self {
        Self {
            converter,
            verbose,
            use_color,
        }
    }

    /// Handle CLI commands
    pub async fn handle_command(&self, command: Commands) -> Result<()> {
        match command {
            Commands::Convert {
                amount,
                from,
                to,
                precision,
                date,
            } => {
                if let Some(historical_date) = date {
                    self.handle_historical_convert(amount, &from, &to, &historical_date, precision)
                        .await
                } else {
                    self.handle_convert(amount, &from, &to, precision).await
                }
            }
            Commands::List { extended, filter } => {
                self.handle_list(extended, filter.as_deref()).await
            }
            Commands::Rates {
                base,
                currencies,
                limit,
                date,
            } => {
                if let Some(historical_date) = date {
                    self.handle_historical_rates(
                        &base,
                        currencies.as_deref(),
                        limit,
                        &historical_date,
                    )
                    .await
                } else {
                    self.handle_rates(&base, currencies.as_deref(), limit).await
                }
            }
            Commands::Compare {
                amount,
                from,
                to,
                date,
            } => {
                if let Some(historical_date) = date {
                    self.handle_historical_compare(amount, &from, &to, &historical_date)
                        .await
                } else {
                    self.handle_compare(amount, &from, &to).await
                }
            }
            Commands::Cache { action } => self.handle_cache_command(action).await,
            Commands::Interactive => self.handle_interactive().await,
        }
    }

    /// Handle currency conversion
    async fn handle_convert(
        &self,
        amount: f64,
        from: &str,
        to: &str,
        precision: u32,
    ) -> Result<()> {
        let spinner = self.create_spinner("Converting currency...");

        let request = ConversionRequest::from_components(amount, from, to)?;

        match self.converter.convert(request).await {
            Ok(result) => {
                spinner.finish_and_clear();

                let rounded_result = result.result.round(precision);

                println!("{}", self.format_header("💱 Currency Conversion"));
                println!();
                println!(
                    "  {} {}",
                    self.colorize("From:", "cyan"),
                    self.colorize(&format!("{}", result.request.from), "white")
                );
                println!(
                    "  {} {}",
                    self.colorize("To:", "cyan"),
                    self.colorize(&format!("{}", rounded_result), "green")
                );
                println!(
                    "  {} {}",
                    self.colorize("Rate:", "cyan"),
                    self.colorize(&format!("{:.6}", result.exchange_rate), "yellow")
                );
                println!(
                    "  {} {}",
                    self.colorize("Type:", "cyan"),
                    self.format_conversion_type(&result.conversion_type)
                );

                if self.verbose {
                    println!(
                        "  {} {}",
                        self.colorize("Timestamp:", "cyan"),
                        self.format_timestamp(result.timestamp)
                    );
                }

                Ok(())
            }
            Err(e) => {
                spinner.finish_and_clear();
                self.print_error(&format!("Conversion failed: {}", e));
                Err(e)
            }
        }
    }

    /// Handle listing currencies
    async fn handle_list(&self, extended: bool, filter: Option<&str>) -> Result<()> {
        let spinner = self.create_spinner("Fetching supported currencies...");

        match self.converter.get_available_currencies().await {
            Ok(mut currencies) => {
                spinner.finish_and_clear();

                // Apply filter if specified
                if let Some(filter_pattern) = filter {
                    let pattern = filter_pattern.to_uppercase();
                    currencies.retain(|c| c.contains(&pattern));
                }

                currencies.sort();

                println!("{}", self.format_header("🌍 Supported Currencies"));

                if extended {
                    self.print_currencies_extended(&currencies);
                } else {
                    self.print_currencies_compact(&currencies);
                }

                println!();
                println!(
                    "{} {} currencies found",
                    self.colorize("Total:", "cyan"),
                    self.colorize(&currencies.len().to_string(), "green")
                );

                Ok(())
            }
            Err(e) => {
                spinner.finish_and_clear();
                self.print_error(&format!("Failed to fetch currencies: {}", e));
                Err(e)
            }
        }
    }

    /// Handle showing exchange rates
    async fn handle_rates(
        &self,
        base: &str,
        currencies: Option<&str>,
        limit: Option<usize>,
    ) -> Result<()> {
        let spinner = self.create_spinner(&format!(
            "Fetching {} exchange rates...",
            base.to_uppercase()
        ));

        match self.converter.exchange_service.get_latest_rates(base).await {
            Ok(rates_response) => {
                spinner.finish_and_clear();

                let mut rates: Vec<(String, f64)> =
                    rates_response.conversion_rates.into_iter().collect();
                rates.sort_by(|a, b| a.0.cmp(&b.0));

                // Filter specific currencies if requested
                if let Some(currency_list) = currencies {
                    let requested_currencies: Vec<String> = currency_list
                        .split(',')
                        .map(|s| s.trim().to_uppercase())
                        .collect();

                    rates.retain(|(code, _)| requested_currencies.contains(code));
                }

                // Apply limit if specified
                if let Some(limit_count) = limit {
                    rates.truncate(limit_count);
                }

                println!(
                    "{}",
                    self.format_header(&format!(
                        "📊 Exchange Rates (Base: {})",
                        base.to_uppercase()
                    ))
                );
                println!();

                for (code, rate) in rates {
                    println!(
                        "  {} {} = {} {}",
                        self.colorize("1", "white"),
                        self.colorize(&base.to_uppercase(), "cyan"),
                        self.colorize(&format!("{:.6}", rate), "green"),
                        self.colorize(&code, "yellow")
                    );
                }

                Ok(())
            }
            Err(e) => {
                spinner.finish_and_clear();
                self.print_error(&format!("Failed to fetch rates: {}", e));
                Err(e)
            }
        }
    }

    /// Handle historical currency conversion
    async fn handle_historical_convert(
        &self,
        amount: f64,
        from: &str,
        to: &str,
        date: &str,
        precision: u32,
    ) -> Result<()> {
        let spinner = self.create_spinner(&format!("Converting currency for {}...", date));

        let request = mudra_cli::api::types::HistoricalConversionRequest {
            amount,
            from: from.to_string(),
            to: to.to_string(),
            date: date.to_string(),
        };

        match self
            .converter
            .exchange_service
            .convert_historical(request)
            .await
        {
            Ok(result) => {
                spinner.finish_and_clear();

                println!(
                    "{}",
                    self.format_header(&format!("💱 Historical Currency Conversion ({})", date))
                );
                println!();
                println!(
                    "  {} {} {} on {}",
                    self.colorize("From:", "cyan"),
                    self.colorize(&format!("{} {}", amount, from.to_uppercase()), "white"),
                    self.colorize("on", "cyan"),
                    self.colorize(date, "white")
                );

                let rounded_amount = (result.conversion_result * 10_f64.powi(precision as i32))
                    .round()
                    / 10_f64.powi(precision as i32);
                println!(
                    "  {} {} {}",
                    self.colorize("To:", "cyan"),
                    self.colorize(
                        &format!(
                            "{:.prec$} {}",
                            rounded_amount,
                            result.target_code,
                            prec = precision as usize
                        ),
                        "green"
                    ),
                    self.colorize(
                        &format!("(historical rate: {:.6})", result.conversion_rate),
                        "yellow"
                    )
                );

                Ok(())
            }
            Err(e) => {
                spinner.finish_and_clear();
                self.print_error(&format!("Historical conversion failed: {}", e));
                Err(e)
            }
        }
    }

    /// Handle historical exchange rates
    async fn handle_historical_rates(
        &self,
        base: &str,
        currencies: Option<&str>,
        limit: Option<usize>,
        date: &str,
    ) -> Result<()> {
        let spinner = self.create_spinner(&format!(
            "Fetching {} exchange rates for {}...",
            base.to_uppercase(),
            date
        ));

        match self
            .converter
            .exchange_service
            .get_historical_rates(base, date)
            .await
        {
            Ok(rates_response) => {
                spinner.finish_and_clear();

                let mut rates: Vec<(String, f64)> =
                    rates_response.conversion_rates.into_iter().collect();
                rates.sort_by(|a, b| a.0.cmp(&b.0));

                // Filter specific currencies if requested
                if let Some(currency_list) = currencies {
                    let requested_currencies: Vec<String> = currency_list
                        .split(',')
                        .map(|s| s.trim().to_uppercase())
                        .collect();

                    rates.retain(|(code, _)| requested_currencies.contains(code));
                }

                // Apply limit if specified
                if let Some(limit_count) = limit {
                    rates.truncate(limit_count);
                }

                println!(
                    "{}",
                    self.format_header(&format!(
                        "📊 Historical Exchange Rates (Base: {}, Date: {})",
                        base.to_uppercase(),
                        date
                    ))
                );
                println!();

                for (code, rate) in rates {
                    println!(
                        "  {} {} = {} {} {}",
                        self.colorize("1", "white"),
                        self.colorize(&base.to_uppercase(), "cyan"),
                        self.colorize(&format!("{:.6}", rate), "green"),
                        self.colorize(&code, "yellow"),
                        self.colorize(&format!("(on {})", date), "white")
                    );
                }

                Ok(())
            }
            Err(e) => {
                spinner.finish_and_clear();
                self.print_error(&format!("Failed to fetch historical rates: {}", e));
                Err(e)
            }
        }
    }

    /// Handle historical currency comparison
    async fn handle_historical_compare(
        &self,
        amount: f64,
        from: &str,
        to_list: &str,
        date: &str,
    ) -> Result<()> {
        let currencies: Vec<&str> = to_list.split(',').map(|s| s.trim()).collect();

        let spinner = self.create_spinner(&format!("Comparing currencies for {}...", date));

        // Get historical rates for the base currency
        match self
            .converter
            .exchange_service
            .get_historical_rates(from, date)
            .await
        {
            Ok(rates) => {
                spinner.finish_and_clear();

                println!(
                    "{}",
                    self.format_header(&format!(
                        "🔄 Historical Currency Comparison ({} {} on {})",
                        amount,
                        from.to_uppercase(),
                        date
                    ))
                );
                println!();

                for currency in currencies {
                    let currency = currency.to_uppercase();
                    match rates.get_rate(&currency) {
                        Some(rate) => {
                            let converted = amount * rate;
                            println!(
                                "  {} {} {} (rate: {:.6})",
                                self.colorize("", "cyan"),
                                self.colorize(&format!("{:.2} {}", converted, currency), "green"),
                                self.colorize(&format!("on {}", date), "white"),
                                self.colorize(&format!("{:.6}", rate), "yellow")
                            );
                        }
                        None => {
                            println!(
                                "  {} {} ({})",
                                self.colorize("", "red"),
                                self.colorize(&currency, "red"),
                                self.colorize("rate not available", "red")
                            );
                        }
                    }
                }

                Ok(())
            }
            Err(e) => {
                spinner.finish_and_clear();
                self.print_error(&format!("Failed to fetch historical rates: {}", e));
                Err(e)
            }
        }
    }

    /// Handle cache management commands
    async fn handle_cache_command(&self, action: CacheAction) -> Result<()> {
        match action {
            CacheAction::Stats => {
                let stats = self.converter.exchange_service.get_cache_stats();

                println!("{}", self.format_header("📈 Cache Statistics"));
                println!();
                println!(
                    "  {} {}",
                    self.colorize("Total Requests:", "cyan"),
                    self.colorize(&stats.total_requests.to_string(), "white")
                );
                println!(
                    "  {} {} ({:.1}%)",
                    self.colorize("Cache Hits:", "cyan"),
                    self.colorize(&stats.hits.to_string(), "green"),
                    self.colorize(&format!("{:.1}", stats.hit_rate), "green")
                );
                println!(
                    "  {} {}",
                    self.colorize("Cache Misses:", "cyan"),
                    self.colorize(&stats.misses.to_string(), "yellow")
                );
                println!(
                    "  {} {}",
                    self.colorize("Expired Entries:", "cyan"),
                    self.colorize(&stats.expired.to_string(), "red")
                );
                println!(
                    "  {} {}",
                    self.colorize("Cached Entries:", "cyan"),
                    self.colorize(&stats.cached_entries.to_string(), "white")
                );
                println!(
                    "  {} {} bytes",
                    self.colorize("Cache Size:", "cyan"),
                    self.colorize(&stats.weighted_size.to_string(), "white")
                );

                Ok(())
            }
            CacheAction::Clear => {
                println!("{}", self.colorize("🗑️  Clearing cache...", "yellow"));
                self.converter.exchange_service.clear_cache().await;
                println!(
                    "{}",
                    self.colorize("✅ Cache cleared successfully", "green")
                );
                Ok(())
            }
            CacheAction::Cleanup => {
                println!(
                    "{}",
                    self.colorize("🧹 Cleaning up expired cache entries...", "yellow")
                );
                self.converter.exchange_service.cleanup_cache().await;
                println!("{}", self.colorize("✅ Cache cleanup completed", "green"));
                Ok(())
            }
        }
    }
    async fn handle_compare(&self, amount: f64, from: &str, to_list: &str) -> Result<()> {
        let currencies: Vec<&str> = to_list.split(',').map(|s| s.trim()).collect();

        let spinner = self.create_spinner("Comparing across currencies...");

        // Create conversion requests for all target currencies
        let mut requests = Vec::new();
        for currency in &currencies {
            match ConversionRequest::from_components(amount, from, currency) {
                Ok(req) => requests.push(req),
                Err(e) => {
                    spinner.finish_and_clear();
                    self.print_error(&format!("Invalid currency {}: {}", currency, e));
                    return Err(e);
                }
            }
        }

        // Perform batch conversion
        let results = self.converter.convert_batch(requests).await;
        spinner.finish_and_clear();

        println!(
            "{}",
            self.format_header(&format!(
                "🔄 Currency Comparison ({} {})",
                amount,
                from.to_uppercase()
            ))
        );
        println!();

        for (i, result) in results.iter().enumerate() {
            match result {
                Ok(conversion) => {
                    let rounded = conversion.result.round(2);
                    println!(
                        "  {} {}",
                        self.colorize("", "cyan"),
                        self.colorize(&format!("{}", rounded), "green")
                    );
                }
                Err(e) => {
                    println!(
                        "  {} {} ({})",
                        self.colorize("", "red"),
                        self.colorize(currencies[i], "red"),
                        self.colorize("failed", "red")
                    );
                    if self.verbose {
                        println!("    {}", self.colorize(&e.to_string(), "red"));
                    }
                }
            }
        }

        Ok(())
    }

    /// Handle interactive mode
    async fn handle_interactive(&self) -> Result<()> {
        println!(
            "{}",
            self.format_header("🎯 Interactive Currency Converter")
        );
        println!("Type 'help' for commands or 'quit' to exit");
        println!();

        loop {
            print!("{} ", self.colorize("mudra>", "cyan"));

            use std::io::{self, Write};
            io::stdout().flush().unwrap();

            let mut input = String::new();
            if io::stdin().read_line(&mut input).is_err() {
                break;
            }

            let input = input.trim();

            if input.is_empty() {
                continue;
            }

            match input {
                "quit" | "exit" | "q" => {
                    println!("{}", self.colorize("Goodbye! 👋", "green"));
                    break;
                }
                "help" | "h" => {
                    self.print_interactive_help();
                }
                cmd => {
                    if let Err(e) = self.handle_interactive_command(cmd).await {
                        self.print_error(&e.to_string());
                    }
                }
            }
        }

        Ok(())
    }

    /// Handle interactive commands
    async fn handle_interactive_command(&self, input: &str) -> Result<()> {
        let parts: Vec<&str> = input.split_whitespace().collect();

        if parts.is_empty() {
            return Ok(());
        }

        // Handle "100 USD EUR" format
        if parts.len() == 3 {
            if let Ok(amount) = parts[0].parse::<f64>() {
                return self.handle_convert(amount, parts[1], parts[2], 2).await;
            }
        }

        // Handle "convert 100 USD EUR" format
        if parts.len() == 4 && parts[0] == "convert" {
            if let Ok(amount) = parts[1].parse::<f64>() {
                return self.handle_convert(amount, parts[2], parts[3], 2).await;
            }
        }

        // Handle "rates USD" format
        if parts.len() == 2 && parts[0] == "rates" {
            return self.handle_rates(parts[1], None, Some(10)).await;
        }

        // Handle "list" format
        if parts.len() == 1 && parts[0] == "list" {
            return self.handle_list(false, None).await;
        }

        Err(CurrencyError::conversion(format!(
            "Invalid command: '{}'. Type 'help' for usage.",
            input
        )))
    }

    /// Create a progress spinner
    fn create_spinner(&self, message: &str) -> ProgressBar {
        let pb = ProgressBar::new_spinner();
        pb.set_style(
            ProgressStyle::default_spinner()
                .template("{spinner:.cyan} {msg}")
                .unwrap(),
        );
        pb.set_message(message.to_string());
        pb.enable_steady_tick(Duration::from_millis(100));
        pb
    }

    /// Format a header with styling
    fn format_header(&self, title: &str) -> String {
        if self.use_color {
            title.bold().blue().to_string()
        } else {
            title.to_string()
        }
    }

    /// Colorize text if colors are enabled
    fn colorize(&self, text: &str, color: &str) -> String {
        if !self.use_color {
            return text.to_string();
        }

        match color {
            "red" => text.red().to_string(),
            "green" => text.green().to_string(),
            "yellow" => text.yellow().to_string(),
            "blue" => text.blue().to_string(),
            "cyan" => text.cyan().to_string(),
            "white" => text.white().to_string(),
            _ => text.to_string(),
        }
    }

    /// Print error message with styling
    fn print_error(&self, message: &str) {
        println!(
            "{} {}",
            self.colorize("❌ Error:", "red"),
            self.colorize(message, "red")
        );
    }

    /// Format conversion type with styling
    fn format_conversion_type(&self, conv_type: &ConversionType) -> String {
        match conv_type {
            ConversionType::SameCurrency => self.colorize("Same Currency", "green"),
            ConversionType::Direct => self.colorize("Direct", "green"),
            ConversionType::Cross { via_currency } => {
                self.colorize(&format!("Cross (via {})", via_currency), "yellow")
            }
        }
    }

    /// Format timestamp
    fn format_timestamp(&self, timestamp: i64) -> String {
        use chrono::DateTime;

        DateTime::from_timestamp(timestamp, 0)
            .map(|dt| dt.format("%Y-%m-%d %H:%M:%S UTC").to_string())
            .unwrap_or_else(|| format!("{}", timestamp))
    }

    /// Print currencies in compact format
    fn print_currencies_compact(&self, currencies: &[String]) {
        const COLUMNS: usize = 6;

        for chunk in currencies.chunks(COLUMNS) {
            let line = chunk
                .iter()
                .map(|c| format!("{:>4}", self.colorize(c, "green")))
                .collect::<Vec<_>>()
                .join("  ");
            println!("  {}", line);
        }
    }

    /// Print currencies in extended format
    fn print_currencies_extended(&self, currencies: &[String]) {
        for currency in currencies {
            println!(
                "  {} {}",
                self.colorize("", "cyan"),
                self.colorize(currency, "green")
            );
        }
    }

    /// Print interactive help
    fn print_interactive_help(&self) {
        println!();
        println!("{}", self.format_header("📖 Interactive Commands"));
        println!();
        println!(
            "  {} {} Convert currency",
            self.colorize("100 USD EUR", "green"),
            self.colorize("", "cyan")
        );
        println!(
            "  {} {} Convert currency",
            self.colorize("convert 100 USD EUR", "green"),
            self.colorize("", "cyan")
        );
        println!(
            "  {} {} Show exchange rates",
            self.colorize("rates USD", "green"),
            self.colorize("", "cyan")
        );
        println!(
            "  {} {} List currencies",
            self.colorize("list", "green"),
            self.colorize("", "cyan")
        );
        println!(
            "  {} {} Show this help",
            self.colorize("help", "green"),
            self.colorize("", "cyan")
        );
        println!(
            "  {} {} Exit",
            self.colorize("quit", "green"),
            self.colorize("", "cyan")
        );
        println!();
    }
}