use camino::Utf8Path;
use crate::error::AppError;
use crate::landing::classify::Intent;
pub fn serves(intent: Intent, target: &Utf8Path) -> Result<(), AppError> {
if !target.exists() {
return Ok(());
}
let classified = crate::services::status::classify_target(target)?;
if intent == Intent::Incremental {
let rule = crate::domain::rule_id::RuleId::IncrementalLandingIsNamed;
if let Some(id) = &classified.migration {
return Err(AppError::Refused(format!(
"the migration {id} is open, so its corpus is archived; close it before an incremental landing ({rule})"
)));
}
return intent
.accepts(classified.classification)
.map_err(|refusal| AppError::Refused(format!("{refusal} ({rule})")));
}
let found = if classified.migration.is_some() {
classified.beneath
} else {
classified.classification
};
intent
.accepts(found)
.map_err(|refusal| AppError::Refused(refusal.to_string()))
}