#ifndef LOTRO_DAT_TEXTSUBFILE_H
#define LOTRO_DAT_TEXTSUBFILE_H

#include "subfile.h"

namespace LOTRO_DAT {
namespace Subfiles {

struct TextFragment {
    long long fragment_id;
    std::u16string text;
    std::string args;

    friend bool operator < (const TextFragment &first, const TextFragment &second) {
        return first.fragment_id < second.fragment_id;
    }
};

template<> class Subfile<TEXT> {
  public:
    static BinaryData BuildForImport(const BinaryData& old_data, const SubfileData& outer_data);

    static SubfileData BuildForExport(const BinaryData& inner_data);
  
  private:
    static std::vector<std::u16string> MakePieces(const BinaryData &data, long long &offset);

    static std::vector<long long> MakeArgumentReferences(const BinaryData &data, long long &offset);

    static std::vector<std::vector<BinaryData>> MakeArgumentStrings(const BinaryData &data, long long &offset);

    static std::vector<TextFragment> ParsePatchFragments(const SubfileData &data);

    static BinaryData BuildPieces(const BinaryData &data, const TextFragment &new_data, long long &offset);

    static BinaryData BuildArgumentReferences(const BinaryData &data, const TextFragment &new_data, long long &offset);

    static BinaryData BuildArgumentStrings(const BinaryData &data, const TextFragment &new_data, long long &offset);

    static BinaryData GetPieceData(const BinaryData &data, long long &offset);

    static BinaryData GetArgumentReferenceData(const BinaryData &data, long long &offset);

    static BinaryData GetArgumentStringsData(const BinaryData &data, long long &offset);
};

}; // namespace Subfiles
}; // namespace LOTRO_DAT

#endif //LOTRO_DAT_TEXTSUBFILE_H
