use serde::Serialize;
use std::path::PathBuf;
#[derive(Clone, Debug, Serialize)]
#[non_exhaustive]
pub struct WorkspaceSnapshot {
pub root: ConfigFileView,
pub rule_sets: Vec<ConfigFileView>,
pub middlewares: Vec<ConfigFileView>,
pub diagnostics: Vec<Diagnostic>,
}
impl WorkspaceSnapshot {
pub fn empty() -> Self {
Self {
root: ConfigFileView::empty(PathBuf::new()),
rule_sets: Vec::new(),
middlewares: Vec::new(),
diagnostics: Vec::new(),
}
}
}
#[derive(Clone, Debug, Serialize)]
#[non_exhaustive]
pub struct ConfigFileView {
pub path: PathBuf,
pub source_relative: Option<String>,
pub nodes: Vec<ConfigNodeView>,
}
impl ConfigFileView {
pub fn empty(path: PathBuf) -> Self {
Self {
path,
source_relative: None,
nodes: Vec::new(),
}
}
}
#[derive(Clone, Debug, Serialize)]
#[non_exhaustive]
pub struct ConfigNodeView {
pub path: String,
pub display_value: String,
pub kind: NodeKind,
pub editable: bool,
}
#[derive(Clone, Copy, Debug, Serialize)]
pub enum NodeKind {
String,
Integer,
Boolean,
StringList,
Table,
}
#[derive(Clone, Debug)]
#[non_exhaustive]
pub enum EditCommand {
AddRuleSet { path: String },
RemoveRuleSet { index: usize },
UpdateField {
target: EditTarget,
path: String,
value: EditValue,
},
SetFallbackRespondDir { path: String },
}
#[derive(Clone, Debug)]
pub enum EditTarget {
Root,
RuleSet { index: usize },
Middleware { index: usize },
}
#[derive(Clone, Debug)]
pub enum EditValue {
String(String),
Integer(i64),
Boolean(bool),
StringList(Vec<String>),
}
#[derive(Clone, Debug, Serialize)]
#[non_exhaustive]
pub struct ApplyResult {
pub ok: bool,
pub modified_files: Vec<PathBuf>,
pub diagnostics: Vec<Diagnostic>,
pub reload_hint: ReloadHint,
}
#[derive(Clone, Copy, Debug, Serialize)]
pub enum ReloadHint {
None,
Reload,
Restart,
}
#[derive(Clone, Debug, Serialize)]
#[non_exhaustive]
pub struct SaveResult {
pub ok: bool,
pub written: Vec<PathBuf>,
pub diagnostics: Vec<Diagnostic>,
}
#[derive(Clone, Debug, Serialize)]
#[non_exhaustive]
pub struct Diagnostic {
pub severity: DiagnosticSeverity,
pub file: Option<PathBuf>,
pub message: String,
}
#[derive(Clone, Copy, Debug, Serialize)]
pub enum DiagnosticSeverity {
Error,
Warning,
Info,
}