#pragma once

#include "FactoryState.h"
#include "GameConfig.h"
#include "Tick.h"

// The queue timer for pending demolitions (REQ-BLD-DECON-QUEUE): one building at a
// time, in parallel with construction. When the front entry's timer elapses the
// building is removed from the world, its tiles are released, and its partial refund
// is credited.
//
// It needs no BeltSystem: a belt, splitter or tunnel end is unregistered the moment
// it is queued (see BuildingSystem::deconstruct), not when the timer completes.
//
// Holds the config alone; the world arrives per tick, the refund going straight into
// the block stock it carries (FactoryState.h).
class DeconstructionSystem
{
public:
    explicit DeconstructionSystem(const GameConfig& config) : m_config(config) {}

    void tick(FactoryState& state, Tick currentTick);

private:
    const GameConfig& m_config;
};

// Starts the timer on the front entry of the deconstruction queue, if it has one and
// it has not started yet. Shared: BuildingSystem::deconstruct starts the timer when it
// queues the first entry, and DeconstructionSystem restarts it after each completion.
void startFrontDeconstruction(FactoryState& state, const GameConfig& config,
                              Tick currentTick);
