package jetbrains.mps.samples.ChemMastery.typesystem;

/*Generated by MPS */

import jetbrains.mps.lang.typesystem.runtime.AbstractNonTypesystemRule_Runtime;
import jetbrains.mps.lang.typesystem.runtime.NonTypesystemRule_Runtime;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.typesystem.inference.TypeCheckingContext;
import jetbrains.mps.lang.typesystem.runtime.IsApplicableStatus;
import jetbrains.mps.internal.collections.runtime.ListSequence;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations;
import jetbrains.mps.errors.messageTargets.MessageTarget;
import jetbrains.mps.errors.messageTargets.NodeMessageTarget;
import jetbrains.mps.errors.IErrorReporter;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import jetbrains.mps.errors.messageTargets.PropertyMessageTarget;
import org.jetbrains.mps.openapi.language.SAbstractConcept;
import org.jetbrains.mps.openapi.language.SContainmentLink;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import org.jetbrains.mps.openapi.language.SConcept;
import org.jetbrains.mps.openapi.language.SProperty;

public class check_ChemEquation_NonTypesystemRule extends AbstractNonTypesystemRule_Runtime implements NonTypesystemRule_Runtime {
  public check_ChemEquation_NonTypesystemRule() {
  }
  public void applyRule(final SNode chemEquation, final TypeCheckingContext typeCheckingContext, IsApplicableStatus status) {
    if (ListSequence.fromList(SLinkOperations.getChildren(chemEquation, LINKS.left$jiYj)).isEmpty()) {
      {
        final MessageTarget errorTarget = new NodeMessageTarget();
        IErrorReporter _reporter_2309309498 = typeCheckingContext.reportTypeError(chemEquation, "The list of chemicals entering the equation is empty", "r:b14d3745-fcf7-4a51-93f8-ba2328d28877(jetbrains.mps.samples.ChemMastery.typesystem)", "7995886393880688056", null, errorTarget);
      }
    }
    if (ListSequence.fromList(SLinkOperations.getChildren(chemEquation, LINKS.right$jjsl)).isEmpty()) {
      {
        final MessageTarget errorTarget = new NodeMessageTarget();
        IErrorReporter _reporter_2309309498 = typeCheckingContext.reportTypeError(chemEquation, "The list of chemicals produced by the equation is empty", "r:b14d3745-fcf7-4a51-93f8-ba2328d28877(jetbrains.mps.samples.ChemMastery.typesystem)", "7995886393880688207", null, errorTarget);
      }
    }
    if (ListSequence.fromList(SLinkOperations.getChildren(chemEquation, LINKS.left$jiYj)).isNotEmpty() && ListSequence.fromList(SLinkOperations.getChildren(chemEquation, LINKS.right$jjsl)).isNotEmpty()) {
      ElementSummary sumL = new ElementSummary(SNodeOperations.ofConcept(SLinkOperations.getChildren(chemEquation, LINKS.left$jiYj), CONCEPTS.Compound$vn));
      ElementSummary sumR = new ElementSummary(SNodeOperations.ofConcept(SLinkOperations.getChildren(chemEquation, LINKS.right$jjsl), CONCEPTS.Compound$vn));
      if (!(sumL.isSameAs(sumR))) {
        {
          final MessageTarget errorTarget = new PropertyMessageTarget(PROPS.condition$jUDn);
          IErrorReporter _reporter_2309309498 = typeCheckingContext.reportTypeError(chemEquation, sumL.comparisonReport(sumR), "r:b14d3745-fcf7-4a51-93f8-ba2328d28877(jetbrains.mps.samples.ChemMastery.typesystem)", "3709490473851308833", null, errorTarget);
        }
      }
    }
  }
  public SAbstractConcept getApplicableConcept() {
    return CONCEPTS.ChemEquation$Xp;
  }
  public IsApplicableStatus isApplicableAndPattern(SNode argument) {
    return new IsApplicableStatus(argument.getConcept().isSubConceptOf(getApplicableConcept()), null);
  }
  public boolean overrides() {
    return false;
  }

  private static final class LINKS {
    /*package*/ static final SContainmentLink left$jiYj = MetaAdapterFactory.getContainmentLink(0xa9a262e8f8054598L, 0x88c614f38937d309L, 0x6ef7184fab9f2133L, 0x6ef7184fab9faa28L, "left");
    /*package*/ static final SContainmentLink right$jjsl = MetaAdapterFactory.getContainmentLink(0xa9a262e8f8054598L, 0x88c614f38937d309L, 0x6ef7184fab9f2133L, 0x6ef7184fab9faa2aL, "right");
  }

  private static final class CONCEPTS {
    /*package*/ static final SConcept Compound$vn = MetaAdapterFactory.getConcept(0xa9a262e8f8054598L, 0x88c614f38937d309L, 0x6ef7184faba62978L, "jetbrains.mps.samples.ChemMastery.structure.Compound");
    /*package*/ static final SConcept ChemEquation$Xp = MetaAdapterFactory.getConcept(0xa9a262e8f8054598L, 0x88c614f38937d309L, 0x6ef7184fab9f2133L, "jetbrains.mps.samples.ChemMastery.structure.ChemEquation");
  }

  private static final class PROPS {
    /*package*/ static final SProperty condition$jUDn = MetaAdapterFactory.getProperty(0xa9a262e8f8054598L, 0x88c614f38937d309L, 0x6ef7184fab9f2133L, 0x6ef7184faba451a7L, "condition");
  }
}
