#include "SalvageScrapExecutor.h"

#include "BehaviorKind.h"
#include "EntityAdmin.h"
#include "MovementIntentComponent.h"
#include "SalvageScrapBehavior.h"
#include "SelectedBehaviorComponent.h"
#include "tracing.h"

void SalvageScrapExecutor::execute(EntityAdmin& admin)
{
    TRACE();
    admin.forEach<SalvageScrapBehavior, SelectedBehaviorComponent,
                  MovementIntentComponent>(
        [](entt::entity /*e*/, const SalvageScrapBehavior& salvage,
           const SelectedBehaviorComponent& selected,
           MovementIntentComponent& intent)
        {
            if (selected.winner != BehaviorKind::SalvageScrap) { return; }
            if (!salvage.debrisTarget) { return; }
            intent = MovementIntentComponent{true, *salvage.debrisTarget,
                                             salvage.orbitRadius_tiles};
        });
}
