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

#ifndef LOTRO_DAT_PATCHER_SUBFILE_H
#define LOTRO_DAT_PATCHER_SUBFILE_H

#include <string>
#include <vector>
#include <yaml-cpp/yaml.h>

extern "C++"
{
namespace LOTRO_DAT
{
    class DatFile;
	class BinaryData;
    class Database;
    class SubfileData;

    enum FILE_TYPE : int;

    class SubFile
    {
        friend class DatFileSystem;
		friend class DatPatcher;

    public:
        struct SubFileOffsetComparator {
            bool operator() (const SubFile &f, const SubFile &s){
                return f.file_offset_ < s.file_offset_;
            }
        };


        SubFile();
        SubFile(const SubFile &other) = default;
		SubFile &operator =(const SubFile &other) = default;

        SubFile(DatFile &dat, const BinaryData &header);
		SubFile(DatFile &dat, long long dictionary_offset, long long fragments_count, 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);
		virtual ~SubFile() = default;

        virtual FILE_TYPE FileType() const;
        virtual std::string Extension() const;

        virtual SubfileData PrepareForExport(const BinaryData &file_data);
        virtual BinaryData MakeForImport(const BinaryData &old_data, const SubfileData &data);
		BinaryData MakeHeaderData() const;

		long long dictionary_offset() const;
        long long unknown1() const;
        long long file_id() const;
        long long file_offset() const;
        long long file_size() const;
        long long timestamp() const;
        long long version() const;
        long long block_size() const;
		long long unknown2() const;

		bool operator ==(const SubFile &b) const;
		bool operator !=(const SubFile &b) const;


        static FILE_TYPE GetSubfileType(DatFile& dat, SubFile preinit_file);
        static std::shared_ptr<SubFile> MakeSubfile(DatFile& dat, SubFile preinit_file);

        long long category;

	protected:
		DatFile *dat_;
        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_;
	};
}
};

#endif //LOTRO_DAT_PATCHER_SUBFILE_H
