use knotra_vcs::model::status::ProjectStatus;
use crate::state::AttentionTier;
#[derive(Debug, Clone, PartialEq, Eq)]
#[allow(dead_code)]
pub enum AttentionCause {
PathNotFound,
Conflict,
ConflictDetectionUnavailable,
DetachedHead,
OperationFailed,
DirtyForLong,
}
pub fn compute_tier(
status: Option<&ProjectStatus>,
path_exists: bool,
) -> (AttentionTier, Option<AttentionCause>) {
if !path_exists {
return (AttentionTier::NeedsAttention, Some(AttentionCause::PathNotFound));
}
let Some(s) = status else {
return (AttentionTier::NeedsAttention, None);
};
if s.conflict.has_conflict {
return (AttentionTier::NeedsAttention, Some(AttentionCause::Conflict));
}
if s.conflict.detection_unavailable {
return (AttentionTier::NeedsAttention, Some(AttentionCause::ConflictDetectionUnavailable));
}
if s.read_error.is_some() {
return (AttentionTier::NeedsAttention, Some(AttentionCause::OperationFailed));
}
let ctx = s.context.as_ref().map(|c| c.label.as_str()).unwrap_or("");
if ctx.starts_with('(') {
return (AttentionTier::NeedsAttention, Some(AttentionCause::DetachedHead));
}
if s.working_tree.uncommitted_count > 0
|| s.working_tree.untracked_count > 0
|| s.remote.ahead > 0
|| s.remote.behind > 0
{
return (AttentionTier::Active, None);
}
if !matches!(ctx, "main" | "master" | "trunk" | "") {
return (AttentionTier::Active, None);
}
(AttentionTier::Clean, None)
}