// ========================================================================================
// You will complete the Simulator class.
// You may edit this file as needed.
// ========================================================================================

#ifndef __SIMULATOR_H__
#define __SIMULATOR_H__

#include <vector>
#include <list>
#include <fstream>

#include "timestamp.h"
#include "job.h"

// The simulator class stores a queue of student submissions awaiting
// autograding, manages which jobs are currently assigned to each
// processor, and tracks statistics to facilitate the analysis of the
// scheduling algorithm.

class Simulator {
public:
  
  // CONSTRUCTOR
  Simulator(const TimeStamp &simulation_start_time,
            int num_processors, const std::string &algorithm,
            const std::string &visualization_file, const std::string &log_file);

  // ACCESSORS
  const TimeStamp& getCurrentTime() { return current; }
  bool done() const;
    
  // MODIFIERS
  void addJob(Job j) { todo.push_back(j); }
  void assignJobs();
  void tick(int sec) { current.addTime(sec); }
  
  // PRINTING
  void printVisualizationRow();
  void printLogRow();
  void printSummaryStatistics(float simulation_running_time);

private:

  // REPRESENTATION
  TimeStamp current;
  int num_processors;
  std::string algorithm;
  std::ofstream vis_str;
  std::ofstream log_str;
  std::vector<Job> processors;

#ifdef VECTOR
  std::vector<Job> todo;
#else
  std::list<Job> todo;
#endif
  
  // statistics
  int job_count;
  int max_waiting_time;
  int total_waiting_time;
  int non_idle_time;
};

#endif
