use crate::discovery::{load_twice, results};
use crate::error::Result;
use crate::grants::attribution::attribution;
use crate::grants::outside::outside;
use crate::grants::plugins::plugin_violations;
use crate::grants::wanted::{sites, wanted};
use crate::placement::layout::Layout;
use crate::ports::{
ContentStore, DeclarationSource, Dispatcher, IgnoreRules, Manifest, RunHistory,
};
use crate::resolve::resolve;
use crate::types::{Checkup, EntryName, Label, MachineFolders};
#[expect(
clippy::too_many_arguments,
reason = "each argument is a distinct port this command reads; grouping them would only rename them"
)]
pub fn doctor<S, I, D, M, H, C>(
source: &S,
rules: &I,
dispatcher: &mut D,
manifest: &M,
entry: &EntryName,
folders: &MachineFolders,
history: &H,
cas: &C,
) -> Result<(Checkup, Vec<Label>)>
where
S: DeclarationSource,
I: IgnoreRules,
D: Dispatcher,
M: Manifest,
H: RunHistory,
C: ContentStore,
{
let loaded = load_twice(source, rules, dispatcher, entry, folders, |labels| {
results(history, cas, labels)
})?;
let graph = resolve(loaded.declarations)?;
let workspace = manifest.workspace()?;
let layout = Layout::of(&graph, &workspace.out)?;
let sites = sites(&graph, graph.settings(), &layout);
let wanted = wanted(&graph, &sites, &workspace);
let outside = outside(&wanted, &workspace);
let attribution = attribution(&graph, graph.settings(), &layout);
let violations = plugin_violations(&graph, graph.settings(), &layout, &workspace);
Ok((
Checkup::new(workspace, wanted, outside, attribution, violations),
loaded.missing,
))
}