#ifndef GERMANAIRLINESVA_FILE_RECORDING_RECORDING_H
#define GERMANAIRLINESVA_FILE_RECORDING_RECORDING_H

#include <cstdint>
#include <fstream>
#include <vector>

#include "constants.h"
#include "recordingEntry.hpp"

namespace germanairlinesva
{
namespace file
{
  namespace recording
  {
    /*
     * Path Recording (6 + n * 24)
     * HEADER | SEGMENTS

     * Header (6)
     * CHAR[5] | UINT8
     * --------+--------
     * VGAR    | VERSION

     * Path Segments (n)
     * PATHSEGMENT[]
     */
    class Recording
    {
      private:
        std::vector<RecordingEntry> entries;

      public:
        template <class... Args> inline void addEntry(Args &&...args)
        {
          this->entries.emplace_back(std::forward<Args>(args)...);
        }

        inline void toFile(std::string fileName) const
        {
          std::ofstream out(BASE_DIRECTORY RECORDING_DIRECTORY + fileName,
                            std::fstream::binary);
          out.write(RECORDING_HEADER, 4);
          out.write("\1", 1);
          for (const RecordingEntry &entry : this->entries) {
            entry.toFile(out);
          }
          out.close();
        }
    };
  } // namespace recording
} // namespace file
} // namespace germanairlinesva

#endif