#pragma once

#include "FactoryQueries.h"

#include <vector>

#include "BeamFiredEvent.h"
#include "Tick.h"

#include "entt/entity/entity.hpp"

class EntityAdmin;

// World-mutation system for salvage modules: each module runs a collection cycle
// on its own cooldown. When a cycle starts it emits a salvage beam toward an
// in-range piece of debris and schedules the collection of one scrap for mid-beam
// (kBeamImpactDelayTicks later) — mirroring weapon firing. Also delivers full
// cargo at a SalvageBay. Runs every tick, independent of behavior selection.
class SalvagerSystem
{
public:
    explicit SalvagerSystem(EntityAdmin& admin);

    void tick(Tick currentTick, FactoryState& state,
              std::vector<BeamFiredEvent>& outBeamFiredEvents);

private:
    struct PendingCollection
    {
        entt::entity ship;
        entt::entity debris;
        Tick         appliesAt;
    };

    void applyPendingCollections(Tick currentTick);

    EntityAdmin&                   m_admin;
    std::vector<PendingCollection> m_pendingCollections;
};
