#include "stdafx.h"

#include "xtr/io/ModelDataExchange.h"

#include "xtr/io/RSExcelIOManager.h"

#include "office/ExcelWrapper.h"

namespace xtr::io {

using ccl::semantic::RSModel;

RSMDataX& RSMDataX::Instance() {
  static RSMDataX instance;
  return instance;
}

BOOL RSMDataX::ExportModel(const RSModel& model) {
  RSExcelIOManager manager{ model };
  try {  
    return manager.ExportModel();
  } catch (_com_error& /*er*/) {
    return FALSE;
  }
}

BOOL RSMDataX::ExportDataFor(EntityUID target, const RSModel& model) {
  RSExcelIOManager manager{ model };
  try { 
    return manager.ExportDataFor(target);
  } catch (_com_error& /*er*/) {
    return FALSE;
  }
}

std::optional<ccl::semantic::TextInterpretation> RSMDataX::ImportText(const RSModel& model) {
  RSExcelIOManager manager{ model };
  try { 
    return manager.ImportText();
  } catch (_com_error& /*er*/) {
    return std::nullopt;
  }
}

std::optional<ccl::object::SDCompact> RSMDataX::ImportStructured(const RSModel& model, const ccl::rslang::Typification& structure) {
  RSExcelIOManager manager{ model };
  try {
    return manager.ImportStructured(structure);
  } catch (_com_error& /*er*/) {
    return std::nullopt;
  }
}

} // namespace xtr::io