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

#include "Subfiles/UnknownSubfile.h"

#include "BinaryData.h"
#include "DatFile.h"
#include "SubfileData.h"
#include "EasyLogging++/easylogging++.h"

namespace LOTRO_DAT {
    UnknownSubfile::UnknownSubfile() = default;

    UnknownSubfile::UnknownSubfile(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)
            : Subfile(dat, dictionary_offset, unknown1, file_id, file_offset, file_size,
                      timestamp, version, block_size, unknown2) {
    }

    FILE_TYPE UnknownSubfile::FileType() const {
        return UNKNOWN;
    }

    std::string UnknownSubfile::Extension() const {
        return std::string(".unknown");
    }

    SubfileData UnknownSubfile::PrepareForExport(const BinaryData &file_data) {
        if (file_data.Empty()) {
            return SubfileData();
        }

        SubfileData result;
        result.binary_data = file_data;
        result.options["fid"] = file_id();
        result.options["ext"] = Extension();
        return result;
    }

    BinaryData UnknownSubfile::MakeForImport(const BinaryData &, const SubfileData &data) {
        if (!data.options["ext"] || data.options["ext"].as<std::string>() != Extension() ||
            !data.options["fid"] || data.options["fid"].as<long long>() != file_id()) {
            LOG(ERROR) << "invalid options data!";
            return BinaryData(0);
        }
        return data.binary_data;
    }
};