use crate::config::Config;
use crate::model::Tier;
use crate::model::doctype::{Form, KeyKind, TypeDef};
use crate::workspace::{Owner, Owners};
pub fn stem(ty: &TypeDef, key: &str, slug: &str) -> String {
match ty.key {
KeyKind::Stamp | KeyKind::Number => format!("{key}-{slug}"),
KeyKind::Slug => slug.to_string(),
}
}
pub fn type_dir(cfg: &Config, owners: &Owners, owner: &Owner, tier: Tier, ty: &TypeDef) -> String {
let own = || crate::config::type_dirs::normalize(ty.dir.as_deref()?).ok();
match tier {
Tier::Committed => match own() {
Some(dir) => owners.within(owner, &dir),
None => format!("{}/{}", owners.spec_dir(owner, cfg.spec_dir()), ty.name),
},
Tier::Local => format!("{}/{}/{}", cfg.local_dir(), owner.id, ty.name),
}
}
pub fn main_file(type_dir: &str, ty: &TypeDef, stem: &str, bundle: bool) -> String {
if bundle || ty.form == Form::Dir {
format!("{type_dir}/{stem}/index.{}.md", ty.name)
} else {
format!("{type_dir}/{stem}.{}.md", ty.name)
}
}