package jetbrains.mps.lang.test.behavior;

/*Generated by MPS */

import jetbrains.mps.errors.item.NodeReportItem;
import org.jetbrains.mps.openapi.model.SNode;
import org.jetbrains.annotations.Nullable;
import jetbrains.mps.errors.MessageStatus;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SConceptOperations;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;

public class NodeRuleFactory {
  private NodeReportItem reporter;

  public NodeRuleFactory(NodeReportItem reporter) {
    this.reporter = reporter;
  }

  public SNode createNodeFromRuleMsg(@Nullable SNode reference) {
    NodeRuleReference ruleReference = new NodeRuleReference(reference);
    if (ruleReference.getType() == RuleType.TYPESYSTEM && !(ruleReference.isReportStatement())) {
      return this.createTypeSystemCheckOperation();
    } else if (ruleReference.getType() == RuleType.CONSTRAINTS) {
      return this.createConstraintsCheckOperation();
    } else if (ruleReference.getType() == RuleType.MESSAGESTATEMENT || ruleReference.getType() == RuleType.TYPESYSTEM && ruleReference.isReportStatement()) {
      return this.createMessageStatementCheckOperation();
    } else {
      return this.createDefaultCheckOperation();
    }
  }

  private SNode createTypeSystemCheckOperation() {
    if (reporter.getSeverity() == MessageStatus.ERROR) {
      return SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0x8585453e6bfb4d80L, 0x98deb16074f1d86cL, 0x5f2a921acc5d63aL, "jetbrains.mps.lang.test.structure.NodeTypeSystemErrorCheckOperation"));
    } else {
      return SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0x8585453e6bfb4d80L, 0x98deb16074f1d86cL, 0x770c2c9f6f1bbfcaL, "jetbrains.mps.lang.test.structure.NodeTypeSystemWarningCheckOperation"));
    }
  }

  private SNode createConstraintsCheckOperation() {
    SNode result;
    if (reporter.getSeverity() == MessageStatus.ERROR) {
      result = SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0x8585453e6bfb4d80L, 0x98deb16074f1d86cL, 0x73a7cdcfba5276dfL, "jetbrains.mps.lang.test.structure.NodeConstraintsErrorCheckOperation"));
    } else {
      result = SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0x8585453e6bfb4d80L, 0x98deb16074f1d86cL, 0x73a7cdcfbbbf8aadL, "jetbrains.mps.lang.test.structure.NodeConstraintsWarningCheckOperation"));
    }
    return result;
  }

  private SNode createMessageStatementCheckOperation() {
    SNode result;
    if (reporter.getSeverity() == MessageStatus.ERROR) {
      result = SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0x8585453e6bfb4d80L, 0x98deb16074f1d86cL, 0x11b01e7283dL, "jetbrains.mps.lang.test.structure.NodeErrorCheckOperation"));
    } else {
      result = SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0x8585453e6bfb4d80L, 0x98deb16074f1d86cL, 0x11b0224b421L, "jetbrains.mps.lang.test.structure.NodeWarningCheckOperation"));
    }
    return result;
  }

  private SNode createDefaultCheckOperation() {
    SNode result;
    if (reporter.getSeverity() == MessageStatus.ERROR) {
      result = SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0x8585453e6bfb4d80L, 0x98deb16074f1d86cL, 0x6cbc57bb7a1917bdL, "jetbrains.mps.lang.test.structure.NodeUnknownErrorCheckOperation"));
    } else {
      result = SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0x8585453e6bfb4d80L, 0x98deb16074f1d86cL, 0x73a7cdcfbbc0b900L, "jetbrains.mps.lang.test.structure.NodeUnknownWarningCheckOperation"));
    }
    return result;
  }

}
