package jetbrains.mps.baseLanguage.money.generator.baseLanguage.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.SNodeOperations;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations;
import jetbrains.mps.baseLanguage.money.generator.baseLanguage.template.util.Util;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.generator.template.SourceSubstituteMacroNodeContext;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SConceptOperations;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations;
import java.util.Map;
import jetbrains.mps.generator.impl.query.ReductionRuleCondition;
import java.util.HashMap;
import org.jetbrains.annotations.NotNull;
import jetbrains.mps.generator.impl.query.QueryKey;
import jetbrains.mps.generator.template.ReductionRuleQueryContext;
import jetbrains.mps.generator.impl.GenerationFailureException;
import jetbrains.mps.generator.impl.query.SourceNodeQuery;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.mps.openapi.language.SContainmentLink;
import org.jetbrains.mps.openapi.language.SConcept;
import org.jetbrains.mps.openapi.language.SProperty;

@Generated
public class QueriesGenerated extends QueryProviderBase {
  public QueriesGenerated() {
    super(1);
  }
  public static boolean rule_Condition_0_0(final BaseMappingRuleContext _context) {
    return SNodeOperations.isInstanceOf(SLinkOperations.getTarget(_context.getNode(), LINKS.creator$BsHW), CONCEPTS.MoneyCreator$Vp);
  }
  public static boolean rule_Condition_0_1(final BaseMappingRuleContext _context) {
    return Util.isPlusMinusExpressionMoneyExpression(_context.getNode());
  }
  public static boolean rule_Condition_0_2(final BaseMappingRuleContext _context) {
    return Util.isPlusMinusExpressionMoneyExpression(_context.getNode());
  }
  public static boolean rule_Condition_0_3(final BaseMappingRuleContext _context) {
    return Util.isMulDivExpressionMoneyExpression(_context.getNode());
  }
  public static boolean rule_Condition_0_4(final BaseMappingRuleContext _context) {
    return Util.isMulDivExpressionMoneyExpression(_context.getNode());
  }
  public static SNode sourceNodeQuery_0_0(final SourceSubstituteMacroNodeContext _context) {
    SNode new_node = SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf93d565d10L, "jetbrains.mps.baseLanguage.structure.StringLiteral"));
    SPropertyOperations.set(new_node, PROPS.value$w7MM, SPropertyOperations.getString(_context.getNode(), PROPS.amount$IcuK));
    return new_node;
  }
  public static SNode sourceNodeQuery_0_1(final SourceSubstituteMacroNodeContext _context) {
    SNode new_node = SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf93d565d10L, "jetbrains.mps.baseLanguage.structure.StringLiteral"));
    SPropertyOperations.set(new_node, PROPS.value$w7MM, SPropertyOperations.getString(_context.getNode(), PROPS.currency$ZpA3));
    return new_node;
  }
  public static SNode sourceNodeQuery_0_2(final SourceSubstituteMacroNodeContext _context) {
    return SLinkOperations.getTarget(SNodeOperations.cast(SLinkOperations.getTarget(_context.getNode(), LINKS.creator$BsHW), CONCEPTS.MoneyCreator$Vp), LINKS.amount$bO09);
  }
  public static SNode sourceNodeQuery_0_3(final SourceSubstituteMacroNodeContext _context) {
    return SLinkOperations.getTarget(SNodeOperations.cast(SLinkOperations.getTarget(_context.getNode(), LINKS.creator$BsHW), CONCEPTS.MoneyCreator$Vp), LINKS.currency$aQMj);
  }
  public static SNode sourceNodeQuery_0_4(final SourceSubstituteMacroNodeContext _context) {
    return SLinkOperations.getTarget(_context.getNode(), LINKS.leftExpression$sEj);
  }
  public static SNode sourceNodeQuery_0_5(final SourceSubstituteMacroNodeContext _context) {
    return SLinkOperations.getTarget(_context.getNode(), LINKS.rightExpression$nvX);
  }
  public static SNode sourceNodeQuery_0_6(final SourceSubstituteMacroNodeContext _context) {
    return SLinkOperations.getTarget(_context.getNode(), LINKS.leftExpression$sEj);
  }
  public static SNode sourceNodeQuery_0_7(final SourceSubstituteMacroNodeContext _context) {
    return SLinkOperations.getTarget(_context.getNode(), LINKS.rightExpression$nvX);
  }
  public static SNode sourceNodeQuery_0_8(final SourceSubstituteMacroNodeContext _context) {
    return SLinkOperations.getTarget(_context.getNode(), LINKS.leftExpression$sEj);
  }
  public static SNode sourceNodeQuery_0_9(final SourceSubstituteMacroNodeContext _context) {
    return SLinkOperations.getTarget(_context.getNode(), LINKS.rightExpression$nvX);
  }
  public static SNode sourceNodeQuery_0_10(final SourceSubstituteMacroNodeContext _context) {
    return SLinkOperations.getTarget(_context.getNode(), LINKS.leftExpression$sEj);
  }
  public static SNode sourceNodeQuery_0_11(final SourceSubstituteMacroNodeContext _context) {
    return SLinkOperations.getTarget(_context.getNode(), LINKS.rightExpression$nvX);
  }
  public static SNode sourceNodeQuery_0_12(final SourceSubstituteMacroNodeContext _context) {
    return SLinkOperations.getTarget(_context.getNode(), LINKS.instance$L2dU);
  }
  public static SNode sourceNodeQuery_0_13(final SourceSubstituteMacroNodeContext _context) {
    return SLinkOperations.getTarget(_context.getNode(), LINKS.instance$L2dU);
  }
  public static SNode sourceNodeQuery_0_14(final SourceSubstituteMacroNodeContext _context) {
    return SLinkOperations.getTarget(_context.getNode(), LINKS.instance$L2dU);
  }
  private final Map<String, ReductionRuleCondition> rrcMethods = new HashMap<String, ReductionRuleCondition>();
  {
    int i = 0;
    rrcMethods.put("1187347245210", new RRC(i++));
    rrcMethods.put("1187344468783", new RRC(i++));
    rrcMethods.put("1187349818788", new RRC(i++));
    rrcMethods.put("1187344489147", new RRC(i++));
    rrcMethods.put("1187344492617", new RRC(i++));
  }
  @Override
  @NotNull
  public ReductionRuleCondition getReductionRuleCondition(@NotNull QueryKey identity) {
    ReductionRuleCondition query = identity.forTemplateNode(rrcMethods);
    return (query != null ? query : super.getReductionRuleCondition(identity));
  }
  private static class RRC implements ReductionRuleCondition {
    private final int methodKey;
    public RRC(int methodKey) {
      this.methodKey = methodKey;
    }
    @Override
    public boolean check(ReductionRuleQueryContext ctx) throws GenerationFailureException {
      switch (methodKey) {
        case 0:
          return QueriesGenerated.rule_Condition_0_0(ctx);
        case 1:
          return QueriesGenerated.rule_Condition_0_1(ctx);
        case 2:
          return QueriesGenerated.rule_Condition_0_2(ctx);
        case 3:
          return QueriesGenerated.rule_Condition_0_3(ctx);
        case 4:
          return QueriesGenerated.rule_Condition_0_4(ctx);
        default:
          throw new GenerationFailureException(String.format("Inconsistent QueriesGenerated: there's no condition method for rule %s (key: #%d)", ctx.getTemplateReference(), methodKey));
      }
    }
  }
  private final Map<String, SourceNodeQuery> snqMethods = new HashMap<String, SourceNodeQuery>();
  {
    int i = 0;
    snqMethods.put("1187347202363", new SNQ(i++));
    snqMethods.put("1187347224873", new SNQ(i++));
    snqMethods.put("2110953167961230052", new SNQ(i++));
    snqMethods.put("2110953167961228859", new SNQ(i++));
    snqMethods.put("1217888347510", new SNQ(i++));
    snqMethods.put("1217888349960", new SNQ(i++));
    snqMethods.put("1217888375666", new SNQ(i++));
    snqMethods.put("1217888321098", new SNQ(i++));
    snqMethods.put("1217888394951", new SNQ(i++));
    snqMethods.put("1187350367397", new SNQ(i++));
    snqMethods.put("1217888412279", new SNQ(i++));
    snqMethods.put("1187350349293", new SNQ(i++));
    snqMethods.put("1217888432992", new SNQ(i++));
    snqMethods.put("1217888379132", new SNQ(i++));
    snqMethods.put("1217888377424", new SNQ(i++));
  }
  @NotNull
  @Override
  public SourceNodeQuery getSourceNodeQuery(@NotNull QueryKey identity) {
    SourceNodeQuery query = identity.forFunctionNode(snqMethods);
    return (query != null ? query : super.getSourceNodeQuery(identity));
  }
  private static class SNQ implements SourceNodeQuery {
    private final int methodKey;
    public SNQ(int methodKey) {
      this.methodKey = methodKey;
    }
    @Nullable
    public SNode evaluate(@NotNull SourceSubstituteMacroNodeContext ctx) throws GenerationFailureException {
      switch (methodKey) {
        case 0:
          return QueriesGenerated.sourceNodeQuery_0_0(ctx);
        case 1:
          return QueriesGenerated.sourceNodeQuery_0_1(ctx);
        case 2:
          return QueriesGenerated.sourceNodeQuery_0_2(ctx);
        case 3:
          return QueriesGenerated.sourceNodeQuery_0_3(ctx);
        case 4:
          return QueriesGenerated.sourceNodeQuery_0_4(ctx);
        case 5:
          return QueriesGenerated.sourceNodeQuery_0_5(ctx);
        case 6:
          return QueriesGenerated.sourceNodeQuery_0_6(ctx);
        case 7:
          return QueriesGenerated.sourceNodeQuery_0_7(ctx);
        case 8:
          return QueriesGenerated.sourceNodeQuery_0_8(ctx);
        case 9:
          return QueriesGenerated.sourceNodeQuery_0_9(ctx);
        case 10:
          return QueriesGenerated.sourceNodeQuery_0_10(ctx);
        case 11:
          return QueriesGenerated.sourceNodeQuery_0_11(ctx);
        case 12:
          return QueriesGenerated.sourceNodeQuery_0_12(ctx);
        case 13:
          return QueriesGenerated.sourceNodeQuery_0_13(ctx);
        case 14:
          return QueriesGenerated.sourceNodeQuery_0_14(ctx);
        default:
          throw new GenerationFailureException(String.format("Inconsistent QueriesGenerated: there's no method for query %s (key: #%d)", ctx.getTemplateReference(), methodKey));
      }
    }
  }

  private static final class LINKS {
    /*package*/ static final SContainmentLink creator$BsHW = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x10ab8473cc5L, 0x10ab847b486L, "creator");
    /*package*/ static final SContainmentLink amount$bO09 = MetaAdapterFactory.getContainmentLink(0xf43135f9b8334685L, 0x8d26ffb6c8215f72L, 0x11472ff5968L, 0x11473383db1L, "amount");
    /*package*/ static final SContainmentLink currency$aQMj = MetaAdapterFactory.getContainmentLink(0xf43135f9b8334685L, 0x8d26ffb6c8215f72L, 0x11472ff5968L, 0x11473390f4aL, "currency");
    /*package*/ static final SContainmentLink leftExpression$sEj = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xfbdeb6fecfL, 0xfbdeb7a11cL, "leftExpression");
    /*package*/ static final SContainmentLink rightExpression$nvX = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xfbdeb6fecfL, 0xfbdeb7a11bL, "rightExpression");
    /*package*/ static final SContainmentLink instance$L2dU = MetaAdapterFactory.getContainmentLink(0xf43135f9b8334685L, 0x8d26ffb6c8215f72L, 0x114740b1673L, 0x114740fc5e3L, "instance");
  }

  private static final class CONCEPTS {
    /*package*/ static final SConcept MoneyCreator$Vp = MetaAdapterFactory.getConcept(0xf43135f9b8334685L, 0x8d26ffb6c8215f72L, 0x11472ff5968L, "jetbrains.mps.baseLanguage.money.structure.MoneyCreator");
  }

  private static final class PROPS {
    /*package*/ static final SProperty value$w7MM = MetaAdapterFactory.getProperty(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf93d565d10L, 0xf93d565d11L, "value");
    /*package*/ static final SProperty amount$IcuK = MetaAdapterFactory.getProperty(0xf43135f9b8334685L, 0x8d26ffb6c8215f72L, 0x1144ae7606aL, 0x1144aec21fdL, "amount");
    /*package*/ static final SProperty currency$ZpA3 = MetaAdapterFactory.getProperty(0xf43135f9b8334685L, 0x8d26ffb6c8215f72L, 0x1144ae7606aL, 0x1144aebdf40L, "currency");
  }
}
