envelope_cli/setup/steps/
categories.rs

1//! Categories setup step
2//!
3//! Allows users to select or customize their category groups.
4
5use std::io::{self, Write};
6
7use crate::error::EnvelopeResult;
8
9/// Category setup choice
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub enum CategoryChoice {
12    /// Use default categories
13    UseDefaults,
14    /// Customize categories (future enhancement)
15    Customize,
16    /// Start with empty categories
17    Empty,
18}
19
20/// Categories setup step result
21pub struct CategoriesSetupResult {
22    /// The user's category choice
23    pub choice: CategoryChoice,
24}
25
26/// Categories setup step
27pub struct CategoriesSetupStep;
28
29impl CategoriesSetupStep {
30    /// Run the categories setup step
31    pub fn run() -> EnvelopeResult<CategoriesSetupResult> {
32        println!();
33        println!("Step 2: Category Groups");
34        println!("=======================");
35        println!();
36        println!("EnvelopeCLI organizes your budget into category groups.");
37        println!();
38        println!("Default groups include:");
39        println!("  - Bills: Rent/Mortgage, Electric, Water, Internet, Phone, Insurance");
40        println!("  - Needs: Groceries, Transportation, Medical, Household");
41        println!("  - Wants: Dining Out, Entertainment, Shopping, Subscriptions");
42        println!("  - Savings: Emergency Fund, Vacation, Large Purchases");
43        println!();
44        println!("What would you like to do?");
45        println!("  1. Use default categories (recommended)");
46        println!("  2. Start with empty categories (add your own later)");
47        println!();
48
49        let choice_str = prompt_string("Select option [1]: ")?;
50        let choice = match choice_str.trim() {
51            "" | "1" => CategoryChoice::UseDefaults,
52            "2" => CategoryChoice::Empty,
53            _ => CategoryChoice::UseDefaults,
54        };
55
56        match choice {
57            CategoryChoice::UseDefaults => {
58                println!();
59                println!("Default categories will be created.");
60            }
61            CategoryChoice::Empty => {
62                println!();
63                println!("Starting with empty categories.");
64                println!("Use 'envelope category create' to add categories later.");
65            }
66            CategoryChoice::Customize => {
67                // Future enhancement
68                println!();
69                println!("Category customization will be available in a future update.");
70                println!("Using default categories for now.");
71            }
72        }
73
74        Ok(CategoriesSetupResult { choice })
75    }
76}
77
78/// Prompt for a string input
79fn prompt_string(prompt: &str) -> EnvelopeResult<String> {
80    print!("{}", prompt);
81    io::stdout().flush()?;
82
83    let mut input = String::new();
84    io::stdin().read_line(&mut input)?;
85
86    Ok(input.trim().to_string())
87}