use chrono::{DateTime, Utc};
use rite_model::{Material, MaterialId, MaterialKind, Prompt, StepFact, StepId};
use secrecy::SecretString;
use crate::system_info::{Environment, SystemInfo};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct PromptId(u64);
impl PromptId {
#[must_use]
pub fn new(value: u64) -> Self {
Self(value)
}
#[must_use]
pub fn value(self) -> u64 {
self.0
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Icon {
Spinner,
Checkmark,
Cross,
Info,
Warning,
}
#[derive(Debug)]
pub enum Response {
Bool(bool),
Text(String),
Secret(SecretString),
Acknowledge,
}
#[derive(Debug, Clone)]
pub struct MaterialOverview {
pub id: MaterialId,
pub title: Option<String>,
pub description: Option<String>,
pub kind: MaterialOverviewKind,
}
#[non_exhaustive]
#[derive(Debug, Clone)]
pub enum MaterialOverviewKind {
Digital,
Physical {
identifier: Option<String>,
quantity: Option<u32>,
},
}
impl MaterialOverviewKind {
#[must_use]
pub fn physical(identifier: Option<String>, quantity: Option<u32>) -> Self {
Self::Physical {
identifier,
quantity,
}
}
}
impl MaterialOverview {
#[must_use]
pub fn display_title(&self) -> &str {
self.title.as_deref().unwrap_or(self.id.as_str())
}
#[must_use]
pub fn from_material(material: &Material) -> Self {
let kind = match &material.kind {
MaterialKind::Digital { .. } => MaterialOverviewKind::Digital,
MaterialKind::Physical {
identifier,
quantity,
} => MaterialOverviewKind::Physical {
identifier: identifier.clone(),
quantity: *quantity,
},
};
Self {
id: material.id.clone(),
title: material.title.clone(),
description: material.description.clone(),
kind,
}
}
}
#[derive(Debug, Clone)]
pub enum UiSignal {
LogLine {
step: Option<StepId>,
icon: Icon,
text: String,
},
Progress {
step: StepId,
phase: String,
fraction: Option<f32>,
},
CeremonyOverview {
description: Option<String>,
materials: Vec<MaterialOverview>,
step_count: usize,
},
SystemInfo(Box<SystemInfo>),
Environment(Environment),
}
#[derive(Debug)]
pub enum ExecEvent {
Fact {
at: DateTime<Utc>,
fact: StepFact,
},
Signal(UiSignal),
AwaitPrompt {
step: Option<StepId>,
prompt_id: PromptId,
prompt: Prompt,
previous_attempt_rejected_because: Option<String>,
},
Finalized {
fingerprint: String,
},
}
#[derive(Debug)]
pub enum UiCommand {
PromptResponse {
prompt_id: PromptId,
response: Response,
},
LogDeviation {
text: String,
},
Abort,
}