//
// Created by Иван_Архипов on 07.11.2017.
//

#ifndef LOTRO_DAT_PATCHER_SUBDIRECTORY_H
#define LOTRO_DAT_PATCHER_SUBDIRECTORY_H

#include <vector>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include "Subfile.h"


extern "C++"
{
namespace LOTRO_DAT
{
    enum FILE_TYPE : int;
    class DatFile;
    class DatException;
    class BinaryData;
    class Subfile;

    class SubDirectory
    {
    public:
        SubDirectory();
        SubDirectory(long long offset, DatFile *dat, long long max_subdirs = 63);
        ~SubDirectory();
        void MakeDictionary(std::map<long long, Subfile*> &dict);

        static std::set<long long> visited_subdirectories_;
    private:
        bool MakeSubDirectories();

        bool MakeSubFiles();
        Subfile* MakeSubfile(long long dictionary_offset, long long unknown1, long long file_id, long long file_offset,
                             long long file_size, long long timestamp, long long version, long long block_size, long long unknown2);

        FILE_TYPE GetSubfileType(long long file_id, long long file_offset) const;
        DatFile *dat_;
        long long offset_;
        long long max_subdirs_;
        std::vector<SubDirectory *> subdirs_;

        std::vector<Subfile *> subfiles_;
    };
}
};

#endif //LOTRO_DAT_PATCHER_SUBDIRECTORY_H
