use crate::level_graph::LevelGraph;
use chrono::{DateTime, Utc};
use code_ranker_plugin_api::Preset;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
pub const SCHEMA_VERSION: &str = "3";
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StageTime {
pub stage: String,
pub ms: u64,
#[serde(default, skip_serializing_if = "String::is_empty")]
pub detail: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Snapshot {
pub schema_version: String,
pub generated_at: DateTime<Utc>,
pub command: String,
pub workspace: String,
pub target: String,
pub plugin: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub config_file: Option<String>,
pub versions: BTreeMap<String, String>,
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub roots: BTreeMap<String, String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub git: Option<GitInfo>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub timings: Vec<StageTime>,
pub graphs: BTreeMap<String, LevelGraph>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub presets: Vec<Preset>,
#[serde(default)]
pub prompt: code_ranker_plugin_api::PromptTemplate,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GitInfo {
pub branch: String,
pub commit: String,
pub dirty_files: u32,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub origin: Option<String>,
}
impl Snapshot {
#[allow(clippy::too_many_arguments)]
pub fn new(
command: String,
workspace: String,
target: String,
plugin: String,
config_file: Option<String>,
versions: BTreeMap<String, String>,
roots: BTreeMap<String, String>,
git: Option<GitInfo>,
timings: Vec<StageTime>,
graphs: BTreeMap<String, LevelGraph>,
presets: Vec<Preset>,
prompt: code_ranker_plugin_api::PromptTemplate,
) -> Self {
Self {
schema_version: SCHEMA_VERSION.to_string(),
generated_at: Utc::now(),
command,
workspace,
target,
plugin,
config_file,
versions,
roots,
git,
timings,
graphs,
presets,
prompt,
}
}
}