#include "stdafx.h"

#include "xtr/doc/RSFacade.h"

namespace xtr::doc {

using ccl::semantic::RSCore;
using ccl::semantic::RSForm;
using ccl::semantic::RSModel;
using ccl::semantic::ConceptRecord;
using ccl::semantic::RSConcept;
using ccl::semantic::TextConcept;
using ccl::semantic::ParsingInfo;
using ccl::semantic::ListIterator;
using ccl::semantic::CstType;

SelectableDoc& RSFacade::Document() noexcept {
  if (isModel) {
    return *modelDoc;
  } else {
    return *schemaDoc;
  }
}

const RSCore& RSFacade::Core() const noexcept {
  if (isModel) {
    return modelDoc->Model().Core();
  } else {
    return schemaDoc->Schema().Core();
  }
}

RSForm& RSFacade::EditSchema() noexcept {
  assert(!isModel);
  return schemaDoc->Schema();
}

const RSForm& RSFacade::Schema() const noexcept {
  assert(!isModel);
  return schemaDoc->Schema();
}

RSModel& RSFacade::EditModel() noexcept {
  assert(isModel);
  return modelDoc->Model();
}

const RSModel& RSFacade::Model() const noexcept {
  assert(isModel);
  return modelDoc->Model();
}

const ccl::semantic::Thesaurus& RSFacade::Texts() const noexcept {
  if (isModel) {
    return modelDoc->Model().Texts();
  } else {
    return schemaDoc->Schema().Texts();
  }
}

const ccl::semantic::Schema& RSFacade::RSLang() const noexcept {
  if (isModel) {
    return modelDoc->Model().RSLang();
  } else {
    return schemaDoc->Schema().RSLang();
  }
}

const ccl::semantic::CstList& RSFacade::List() const noexcept {
  if (isModel) {
    return modelDoc->Model().List();
  } else {
    return schemaDoc->Schema().List();
  }
}

bool RSFacade::Contains(const EntityUID entity) const {
  if (isModel) {
    return modelDoc->Model().Contains(entity);
  } else {
    return schemaDoc->Schema().Contains(entity);
  }
}

const RSConcept& RSFacade::GetRS(const EntityUID entity) const {
  if (isModel) {
    return modelDoc->Model().GetRS(entity);
  } else {
    return schemaDoc->Schema().GetRS(entity);
  }
}

const TextConcept& RSFacade::GetText(const EntityUID entity) const {
  if (isModel) {
    return modelDoc->Model().GetText(entity);
  } else {
    return schemaDoc->Schema().GetText(entity);
  }
}

const ParsingInfo& RSFacade::GetParse(const EntityUID entity) const {
  if (isModel) {
    return modelDoc->Model().GetParse(entity);
  } else {
    return schemaDoc->Schema().GetParse(entity);
  }
}

void RSFacade::SetComment(const std::string& newComment) {
  if (isModel) {
    modelDoc->Model().comment = newComment;
  } else {
    schemaDoc->Schema().comment = newComment;
  }
}

bool RSFacade::SetExpressionFor(const EntityUID target, const std::string& expression) {
  if (isModel) {
    return modelDoc->Model().SetExpressionFor(target, expression);
  } else {
    return schemaDoc->Schema().SetExpressionFor(target, expression);
  }
}

bool RSFacade::SetTermFor(const EntityUID target, const std::string& termRef) {
  if (isModel) {
    return modelDoc->Model().SetTermFor(target, termRef);
  } else {
    return schemaDoc->Schema().SetTermFor(target, termRef);
  }
}

bool RSFacade::SetTermFormFor(const EntityUID target, const std::string& termRef, const ccl::lang::Morphology& form) {
  if (isModel) {
    return modelDoc->Model().SetTermFormFor(target, termRef, form);
  } else {
    return schemaDoc->Schema().SetTermFormFor(target, termRef, form);
  }
}

bool RSFacade::SetDefinitionFor(const EntityUID target, const std::string& textDef) {
  if (isModel) {
    return modelDoc->Model().SetDefinitionFor(target, textDef);
  } else {
    return schemaDoc->Schema().SetDefinitionFor(target, textDef);
  }
}

bool RSFacade::SetConventionFor(const EntityUID target, const std::string& convention) {
  if (isModel) {
    return modelDoc->Model().SetConventionFor(target, convention);
  } else {
    return schemaDoc->Schema().SetConventionFor(target, convention);
  }
}

bool RSFacade::SetAliasFor(const EntityUID target, const std::string& newName, const bool substitue) {
  if (isModel) {
    return modelDoc->Model().SetAliasFor(target, newName, substitue);
  } else {
    return schemaDoc->Schema().SetAliasFor(target, newName, substitue);
  }
}

void RSFacade::ResetAliases() {
  if (isModel) {
    return modelDoc->Model().ResetAliases();
  } else {
    return schemaDoc->Schema().ResetAliases();
  }
}

EntityUID RSFacade::Emplace(const CstType type, const std::string& definition) {
  if (isModel) {
    return modelDoc->Model().Emplace(type, definition);
  } else {
    return schemaDoc->Schema().Emplace(type, definition);
  }
}

VectorOfEntities RSFacade::InsertCopy(const std::vector<ConceptRecord>& input) {
  if (isModel) {
    return modelDoc->Model().InsertCopy(input);
  } else {
    return schemaDoc->Schema().InsertCopy(input);
  }
}

bool RSFacade::MoveBefore(const EntityUID what, const ListIterator iWhere) {
  if (isModel) {
    return modelDoc->Model().MoveBefore(what, iWhere);
  } else {
    return schemaDoc->Schema().MoveBefore(what, iWhere);
  }
}

} // namespace xtr::doc