#ifndef DIRECTORYNODE_H_
#define DIRECTORYNODE_H_
class Print;

#include <SD.h>
#include <vector>






class DirectoryNode {
private:
  uint16_t id;
  String name;
  String dirPath;
  std::vector<DirectoryNode*> subdirectories;
  std::vector<String> mp3Files;
  std::vector<uint16_t> ids;
  static const size_t path_size = 256;
  String currentPlaying;
  uint16_t currentPlayingId = 0;
  uint16_t secondsPlayed = 0;
  static const size_t buffer_size = path_size;
  static char buffer[buffer_size];
  
  String buildFullPath(const String& fileName) const;
  void buildFullPath(const String &fileName, char* buffer, size_t bufferSize) const;
  bool comparePathWithString(const char* path, const String& target) const;

   

public:
  DirectoryNode(const String& nodeName);
  ~DirectoryNode();
  static uint16_t idCounter;
  

  const String& getName() const;
  const uint16_t getId() const;
  const std::vector<DirectoryNode*>& getSubdirectories() const;
  const std::vector<String>& getMP3Files() const;
  const String& getDirPath() const;
  uint16_t getFileIdAt(size_t i) const;

  size_t getNumOfFiles() const;

  void setCurrentPlaying(const String& mp3File);
  const String& getCurrentPlaying() const;
  const uint16_t getCurrentPlayingId() const;

  void setSecondsPlayed(const uint32_t seconds);
  uint32_t getSecondsPlayed() const;

  uint16_t getNextId();

  void addSubdirectory(DirectoryNode* subdirectory);
  void addMP3File(const String& mp3File);
  void buildDirectoryTree(const char* currentPath);
  void printDirectoryTree(int level = 0) const;
  DirectoryNode* advanceToMP3(const String& songName);
  DirectoryNode* advanceToNextMP3(const String& currentGlobal);
  DirectoryNode* goToPreviousMP3(uint32_t thresholdSeconds = 3);
  DirectoryNode* findPreviousMP3Globally(const String& currentGlobal);
  void buildFlatMP3List(std::vector<std::pair<DirectoryNode*, int>>& allMP3s);
  DirectoryNode* advanceToMP3(const uint16_t id);
  void advanceToFirstMP3InThisNode();
  DirectoryNode* findFirstDirectoryWithMP3s();
};




#endif /* DIRECTORYNODE_H_ */
