Skip to main content

hyprstream_tui/wizard/
phases.rs

1//! Wizard phase definitions and screen state machines.
2
3use waxterm::widgets::{ConfirmDialog, MultiSelectList, SelectList, TextInput};
4
5use super::backend::{EnvironmentInfo, InstallAction, LibtorchVariant, TemplateInfo};
6
7/// Top-level wizard phase.
8pub enum WizardPhase {
9    Install(InstallScreen),
10    Bootstrap(BootstrapScreen),
11    PolicyTemplate(PolicyScreen),
12    Users(UserScreen),
13    Tokens(TokenScreen),
14    Services(ServiceScreen),
15    Summary(SummaryScreen),
16}
17
18// ─────────────────────────────────────────────────────────────────────────────
19// Phase 1: Install / Update
20// ─────────────────────────────────────────────────────────────────────────────
21
22pub enum InstallScreen {
23    /// Auto-detecting environment.
24    Detecting,
25    /// Show findings and recommendation.
26    ShowFindings {
27        env: EnvironmentInfo,
28        action: InstallAction,
29    },
30    /// User chose to pick variant manually.
31    SelectVariant(SelectList<String>),
32    /// Download + install in progress.
33    Installing {
34        variant: LibtorchVariant,
35        progress_pct: u8,
36        status_msg: String,
37    },
38    /// Completed.
39    Done(String),
40    /// User skipped.
41    Skipped,
42    /// Failed with option to retry.
43    Failed(String),
44}
45
46// ─────────────────────────────────────────────────────────────────────────────
47// Phase 2: Bootstrap
48// ─────────────────────────────────────────────────────────────────────────────
49
50pub struct BootstrapScreen {
51    pub started: bool,
52    pub completed_steps: Vec<String>,
53    pub current_step: String,
54    pub done: bool,
55    pub failed: Option<String>,
56}
57
58impl Default for BootstrapScreen {
59    fn default() -> Self {
60        Self::new()
61    }
62}
63
64impl BootstrapScreen {
65    pub fn new() -> Self {
66        Self {
67            started: false,
68            completed_steps: Vec::new(),
69            current_step: String::new(),
70            done: false,
71            failed: None,
72        }
73    }
74}
75
76// ─────────────────────────────────────────────────────────────────────────────
77// Phase 3: Policy Template
78// ─────────────────────────────────────────────────────────────────────────────
79
80pub enum PolicyScreen {
81    /// Ask if user wants to replace existing policy.
82    ConfirmReplace(ConfirmDialog),
83    /// Select from template list.
84    SelectTemplate(SelectList<String>),
85    /// Template applied, showing result.
86    Applied(String),
87    /// User skipped or kept existing.
88    Skipped,
89}
90
91impl PolicyScreen {
92    /// Build the template selection list from backend data.
93    pub fn select_from(templates: &[TemplateInfo]) -> Self {
94        let mut options: Vec<String> = templates
95            .iter()
96            .map(|t| format!("{} — {}", t.name, t.description))
97            .collect();
98        options.push("None — skip template".to_string());
99        PolicyScreen::SelectTemplate(SelectList::new("Select a policy template:", options))
100    }
101}
102
103// ─────────────────────────────────────────────────────────────────────────────
104// Phase 4: Users & Roles
105// ─────────────────────────────────────────────────────────────────────────────
106
107pub enum UserScreen {
108    /// Ask if user wants to add a user.
109    AskAdd(ConfirmDialog),
110    /// Enter username.
111    EnterName(TextInput),
112    /// Select role.
113    SelectRole(SelectList<String>),
114    /// For custom role: enter resource pattern.
115    CustomResource(TextInput),
116    /// For custom role: select actions.
117    CustomActions(MultiSelectList<String>),
118    /// Ask to add another user.
119    AskAnother(ConfirmDialog),
120    /// Done with user creation.
121    Done,
122}
123
124/// Record of a created user.
125#[derive(Debug, Clone)]
126pub struct UserRecord {
127    pub username: String,
128    pub role: String,
129}
130
131/// Record of a generated token.
132#[derive(Debug, Clone)]
133pub struct TokenRecord {
134    pub username: String,
135    pub token: String,
136    pub expires: String,
137}
138
139// ─────────────────────────────────────────────────────────────────────────────
140// Phase 5: Tokens
141// ─────────────────────────────────────────────────────────────────────────────
142
143pub enum TokenScreen {
144    /// Ask if user wants to generate a token.
145    AskGenerate(ConfirmDialog, String),
146    /// Select expiration.
147    SelectExpiry(SelectList<String>, String),
148    /// Show generated token.
149    ShowToken(TokenRecord),
150    /// Ask for next user's token.
151    NextUser,
152    /// Done with token generation.
153    Done,
154}
155
156// ─────────────────────────────────────────────────────────────────────────────
157// Phase 6: Services
158// ─────────────────────────────────────────────────────────────────────────────
159
160pub enum ServiceScreen {
161    /// Ask if user wants to start services.
162    AskStart(ConfirmDialog),
163    /// Services starting.
164    Starting,
165    /// Done.
166    Done(bool),
167}
168
169// ─────────────────────────────────────────────────────────────────────────────
170// Summary
171// ─────────────────────────────────────────────────────────────────────────────
172
173pub struct SummaryScreen {
174    pub install_result: Option<String>,
175    pub templates_applied: Vec<String>,
176    pub users_created: Vec<UserRecord>,
177    pub tokens_generated: Vec<TokenRecord>,
178    pub services_started: bool,
179}