use std::path::PathBuf;
use serde::{Deserialize, Serialize};
use crate::{ArenaId, ByteSize, RepositoryId, ToolchainId, WorkspaceId, WorktreeId};
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "snake_case", tag = "kind", content = "code")]
pub enum BuildOutcome {
NotStarted,
Succeeded,
Failed(i32),
Terminated,
}
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum ArenaState {
Active,
Suspect,
Pinned,
Orphaned,
Idle,
}
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum ArenaLiveness {
#[default]
Inactive,
Active,
Suspect,
}
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum SizeQuality {
#[default]
Fresh,
Cached,
Stale,
Unknown,
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ArenaRecord {
pub id: ArenaId,
pub repository_id: RepositoryId,
pub worktree_id: WorktreeId,
pub workspace_id: WorkspaceId,
pub toolchain_id: ToolchainId,
pub worktree_root: PathBuf,
pub build_dir: PathBuf,
pub size: ByteSize,
pub size_quality: SizeQuality,
pub created_at: u64,
pub last_used_at: u64,
pub liveness: ArenaLiveness,
pub pinned: bool,
pub worktree_exists: bool,
pub last_outcome: Option<BuildOutcome>,
}
impl ArenaRecord {
pub const fn state(&self) -> ArenaState {
if matches!(self.liveness, ArenaLiveness::Active) {
ArenaState::Active
} else if matches!(self.liveness, ArenaLiveness::Suspect) {
ArenaState::Suspect
} else if self.pinned {
ArenaState::Pinned
} else if !self.worktree_exists {
ArenaState::Orphaned
} else {
ArenaState::Idle
}
}
}