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

#ifndef LOTRO_DAT_PATCHER_SUBFILE_H
#define LOTRO_DAT_PATCHER_SUBFILE_H
#include <string>

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

    enum EXTENSION
    {
        TXT, JPG, DDS, WAV, OGG, FONT, UNKNOWN
    };

    class Subfile
    {
    public:
        Subfile();

        Subfile(DatFile *dat, 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);

        bool ExportFile(const char* filename, Database *db = nullptr) const;
		
		bool ExportFileAsTXT(const char *filename, Database *db = nullptr) const; // Need to have special function,
																						 // as TXT file consisits of more than 1 file
		bool PatchFile();

        long long fragments_count() 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;

		EXTENSION ext() const;
    
	private:
        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_;

        bool compressed_;

        DatFile *dat_;
		EXTENSION ext_;

		EXTENSION GetExtension() const;
		std::string ExtensionToString(LOTRO_DAT::EXTENSION ext) const;

		BinaryData GetFileData(long long offset = 8) const;

		const BinaryData PrepareAsJPG() const;
		const BinaryData PrepareAsDDS() const;
		const BinaryData PrepareAsOGG() const;
		const BinaryData PrepareAsFont() const;
		const BinaryData PrepareAsWAV() const;
		const BinaryData PrepareAsUnk() const;
    };
}
};


#endif //LOTRO_DAT_PATCHER_SUBFILE_H
