use crate::collision_kind::CollisionKind;
use crate::lc_action_config::LcActionConfig;
use crate::lc_entity::LcEntity;
use crate::lc_entity_type::LcEntityType;

pub fn run_lca<T: LcEntityType>(
    action: &LcActionConfig<T>,
    source: &LcEntity<T>,
    target: &LcEntity<T>,
) {
    for action_config in &action.data {
        let contains_self = action_config.collision.contains(CollisionKind::SELF);
        let contains_self_kind = action_config.collision.contains(CollisionKind::SAME_KIND);
        let contains_others = action_config.collision.contains(CollisionKind::OTHER);

        let is_same_kind = source.type_id() == target.type_id();

        if contains_self {
            action_config.action.apply(source, source);
        }
        if contains_self_kind && is_same_kind {
            action_config.action.apply(source, target);
        }
        if contains_others && !is_same_kind {
            action_config.action.apply(source, target);
        }
    }
}
