#pragma once

#include "xtr/doc/RSModelDoc.h"

namespace xtr::io {

//! RSM legacy loader
class RSMLegacyLoader {
  io::CArchiveAdapter& ar;
  ccl::semantic::RSModel& model;
  
  SetOfEntities calculated{};

public:
  RSMVersion version{ RSMVersion::old };
  SetOfEntities selection{};

public:
  RSMLegacyLoader(CArchiveAdapter& ar, ccl::semantic::RSModel& model)
    : ar{ ar }, model{ model } {}

public:
  using LegacyData = std::vector<std::vector<int32_t>>;
  void LoadVersion();
  void DoLoad();

private:
  void LoadFirstGen();
  void LoadCst();
  void LoadCstData();
  LegacyData LoadRSITable();
  ccl::semantic::TextInterpretation LoadTextData(BOOL skipIndex);
  
  void LoadSecondGen();
  void LoadDataFor(EntityUID uid);

  void LoadModelProperties(BOOL loadModelName);
};

} // namespace xtr::io