wowlab_cli/commands/snapshot/
assisted_rotas.rs1mod conditions;
4mod dsl;
5mod output;
6mod preparation;
7#[cfg(test)]
8mod tests;
9
10use anyhow::{Result, anyhow};
11use wowlab_parsers::{DbcData, transform_assisted_rotation, transform_assisted_rotations};
12
13use super::{AssistedRotasArgs, AssistedRotasMode};
14
15pub(super) async fn run_assisted_rotas(args: AssistedRotasArgs) -> Result<()> {
16 let dbc = DbcData::load_all(&args.data_dir)?;
17 let assisted = if let Some(spec_id) = args.spec_id {
18 let rotation = transform_assisted_rotation(&dbc, spec_id).ok_or_else(|| {
19 anyhow!(
20 "no assisted-combat rotation for spec {spec_id} in {} — \
21 is --data-dir the wowlab-data repo root?",
22 args.data_dir.display()
23 )
24 })?;
25
26 if rotation.actions.is_empty() {
27 return Err(anyhow!(
28 "assisted-combat rotation for spec {spec_id} has no actions — \
29 refusing to write an empty rotation (check --data-dir)"
30 ));
31 }
32
33 vec![rotation]
34 } else {
35 transform_assisted_rotations(&dbc)
36 };
37
38 let prepared = preparation::prepare_rotations(&dbc, &assisted, &args);
39
40 if matches!(args.mode, AssistedRotasMode::Dump | AssistedRotasMode::Both) {
41 output::write_rotation_dumps(&args.out_dir, &prepared)?;
42 }
43
44 if matches!(
45 args.mode,
46 AssistedRotasMode::Upsert | AssistedRotasMode::Both
47 ) {
48 let user_id = args.user_id.as_deref().ok_or_else(|| {
49 anyhow!("--user-id is required when --mode is upsert or both (must be a valid UUID)")
50 })?;
51
52 output::upsert_rotations(user_id, args.is_public, &prepared).await?;
53 }
54
55 Ok(())
56}