#pragma once
#include "factory/core/simulation.h"
#include <condition_variable>
#include <memory>
#include <mutex>
#include <thread>

namespace factory {
class SimulationService {
public:
  ~SimulationService();
  void start(Project project, bool playing = true);
  void stop();
  void setPlaying(bool playing);
  bool playing() const;
  bool active() const;
  void setSpeed(int speed);
  void stepOnce();
  Snapshot snapshot() const;

private:
  mutable std::mutex mutex_;
  std::condition_variable_any wake_;
  std::unique_ptr<Simulation> simulation_;
  std::jthread worker_;
  bool playing_{};
  int speed_{1};
};
} // namespace factory
