package jetbrains.mps.transformation.test.errorReporting.generator.template.main;

/*Generated by MPS */

import jetbrains.mps.generator.runtime.Generated;
import jetbrains.mps.generator.impl.query.QueryProviderBase;
import jetbrains.mps.generator.template.BaseMappingRuleContext;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.generator.template.WeavingMappingRuleContext;
import java.util.Map;
import java.util.HashMap;
import org.jetbrains.annotations.NotNull;
import jetbrains.mps.generator.impl.query.WeaveRuleCondition;
import jetbrains.mps.generator.impl.query.QueryKey;
import jetbrains.mps.generator.impl.query.WeaveRuleQuery;
import jetbrains.mps.generator.impl.query.WeaveAnchorQuery;
import jetbrains.mps.generator.impl.GenerationFailureException;
import org.jetbrains.annotations.Nullable;
import jetbrains.mps.generator.template.WeavingAnchorContext;
import org.jetbrains.mps.openapi.language.SProperty;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;

@Generated
public class QueriesGenerated extends QueryProviderBase {
  public QueriesGenerated() {
    super(1);
  }
  public static boolean rule_Condition_0_0(final BaseMappingRuleContext _context) {
    return SPropertyOperations.getInteger(_context.getNode(), PROPS.intval$ETgn) == 42;
  }
  public static SNode weavingRule_ContextQuery_0_0(final WeavingMappingRuleContext _context) {
    return null;
  }
  public static SNode weavingRule_ContextQuery_0_1(final WeavingMappingRuleContext _context) {
    return _context.getOutputNodeByMappingLabel("aaa", null);
  }
  private final Map<String, WRQ> wrcnMethods = new HashMap<String, WRQ>();
  {
    int i = 0;
    wrcnMethods.put("7287346816896128674", new WRQ(i++));
    wrcnMethods.put("6145560071556216090", new WRQ(i++));
  }
  @Override
  @NotNull
  public WeaveRuleCondition getWeaveRuleCondition(@NotNull QueryKey identity) {
    WRQ query = identity.forTemplateNode(wrcnMethods);
    return (query != null ? query : super.getWeaveRuleCondition(identity));
  }
  @Override
  @NotNull
  public WeaveRuleQuery getWeaveRuleQuery(@NotNull QueryKey identity) {
    WRQ query = identity.forTemplateNode(wrcnMethods);
    return (query != null ? query : super.getWeaveRuleQuery(identity));
  }
  @NotNull
  @Override
  public WeaveAnchorQuery getWeaveAnchorQuery(@NotNull QueryKey identity) {
    WRQ query = identity.forTemplateNode(wrcnMethods);
    return (query != null ? query : super.getWeaveAnchorQuery(identity));
  }
  private static class WRQ implements WeaveRuleQuery, WeaveRuleCondition, WeaveAnchorQuery {
    private final int methodKey;
    public WRQ(int methodKey) {
      this.methodKey = methodKey;
    }
    @Override
    public boolean check(@NotNull WeavingMappingRuleContext ctx) throws GenerationFailureException {
      switch (methodKey) {
        case 0:
          return QueriesGenerated.rule_Condition_0_0(ctx);
        case 1:
          return true;
        default:
          throw new GenerationFailureException(String.format("Inconsistent QueriesGenerated: there's no condition method for rule %s (key: #%d)", ctx.getTemplateReference(), methodKey));
      }
    }
    @Override
    public SNode contextNode(WeavingMappingRuleContext ctx) throws GenerationFailureException {
      switch (methodKey) {
        case 0:
          return QueriesGenerated.weavingRule_ContextQuery_0_0(ctx);
        case 1:
          return QueriesGenerated.weavingRule_ContextQuery_0_1(ctx);
        default:
          throw new GenerationFailureException(String.format("Inconsistent QueriesGenerated: there's no context node query method for weaving rule %s (key: #%d)", ctx.getTemplateReference(), methodKey));
      }

    }
    @Nullable
    @Override
    public SNode anchorNode(WeavingAnchorContext ctx) throws GenerationFailureException {
      switch (methodKey) {
        case 0:
          return null;
        case 1:
          return null;
        default:
          throw new GenerationFailureException(String.format("Inconsistent QueriesGenerated: there's no anchor query method for rule %s (key: #%d)", ctx.getTemplateReference(), methodKey));
      }
    }
  }

  private static final class PROPS {
    /*package*/ static final SProperty intval$ETgn = MetaAdapterFactory.getProperty(0x99a58581851840c8L, 0x81f1e364306f5ffcL, 0x6521db51e82a7653L, 0x6521db51e82a9208L, "intval");
  }
}
