use crate::error::OrbokError;
use serde::{Deserialize, Serialize};
macro_rules! catalog_enum {
($(#[$doc:meta])* $name:ident, $column:literal, { $($variant:ident => $s:literal),+ $(,)? }) => {
$(#[$doc])*
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum $name {
$($variant),+
}
impl $name {
pub fn as_str(&self) -> &'static str {
match self {
$(Self::$variant => $s),+
}
}
pub fn parse(s: &str) -> Result<Self, OrbokError> {
match s {
$($s => Ok(Self::$variant),)+
other => Err(OrbokError::InvalidCatalogValue {
column: $column,
value: other.to_string(),
}),
}
}
}
};
}
catalog_enum!(
SourceType,
"sources.source_type",
{ Directory => "directory", File => "file" }
);
catalog_enum!(
PersistenceMode,
"sources.persistence_mode",
{ Persistent => "persistent", Temporary => "temporary" }
);
catalog_enum!(
SourceStatus,
"sources.status",
{
Active => "active",
Paused => "paused",
Missing => "missing",
PermissionDenied => "permission_denied",
Removed => "removed",
}
);
catalog_enum!(
IndexMode,
"sources.index_mode",
{
Balanced => "balanced",
HighAccuracy => "high_accuracy",
SpaceSaving => "space_saving",
}
);
catalog_enum!(
HiddenFilePolicy,
"sources.hidden_file_policy",
{ Exclude => "exclude", Include => "include", Warn => "warn" }
);
catalog_enum!(
SymlinkPolicy,
"sources.symlink_policy",
{
Ignore => "ignore",
FollowWithinSource => "follow_within_source",
FollowAllWithWarning => "follow_all_with_warning",
}
);
catalog_enum!(
FileStatus,
"files.file_status",
{
Discovered => "discovered",
Indexed => "indexed",
Stale => "stale",
Missing => "missing",
Deleted => "deleted",
PermissionDenied => "permission_denied",
Unsupported => "unsupported",
Failed => "failed",
}
);
catalog_enum!(
JobType,
"index_jobs.job_type",
{
Scan => "scan",
Extract => "extract",
Chunk => "chunk",
KeywordIndex => "keyword_index",
Embedding => "embedding",
DeleteStale => "delete_stale",
Rebuild => "rebuild",
}
);
catalog_enum!(
JobStatus,
"index_jobs.status",
{
Queued => "queued",
Running => "running",
Succeeded => "succeeded",
Failed => "failed",
Canceled => "canceled",
Blocked => "blocked",
}
);
impl Default for HiddenFilePolicy {
fn default() -> Self {
HiddenFilePolicy::Exclude
}
}
impl Default for SymlinkPolicy {
fn default() -> Self {
SymlinkPolicy::Ignore
}
}
impl Default for IndexMode {
fn default() -> Self {
IndexMode::Balanced
}
}