use super::EffectContext;
use crate::ability::ability_ir::DefinedRef;
use crate::ids::CardId;
use forge_foundation::ZoneType;
#[manabrew_engine_macros::spell_effect(UnattachEffect)]
fn resolve(ctx: &mut EffectContext, sa: &crate::spellability::SpellAbility) {
let cards: Vec<CardId> = if sa.uses_targeting() {
sa.target_chosen.target_card.into_iter().collect()
} else if let Some(defined) = sa.defined_ref() {
if matches!(defined, DefinedRef::SelfCard) {
sa.source.into_iter().collect()
} else {
Vec::new()
}
} else {
sa.source.into_iter().collect()
};
for card_id in cards {
if ctx.game.card(card_id).zone != ZoneType::Battlefield {
continue;
}
let attached_to = ctx.game.card(card_id).attached_to;
if let Some(host_id) = attached_to {
ctx.game.card_mut(host_id).remove_attachment(card_id);
ctx.game.card_mut(card_id).set_attached_to(None);
}
}
}