package jetbrains.mps.samples.KajaSceneConstruction.generator.template.main;

/*Generated by MPS */

import jetbrains.mps.generator.runtime.Generated;
import jetbrains.mps.generator.runtime.TemplateDeclarationBase;
import org.jetbrains.mps.openapi.model.SNodeReference;
import jetbrains.mps.smodel.SNodePointer;
import jetbrains.mps.generator.runtime.FragmentResult;
import org.jetbrains.annotations.NotNull;
import jetbrains.mps.generator.runtime.TemplateContext;
import jetbrains.mps.generator.runtime.GenerationException;
import jetbrains.mps.generator.runtime.TemplateExecutionEnvironment;
import org.jetbrains.mps.openapi.model.SNode;
import org.jetbrains.mps.openapi.model.SNodeAccessUtil;
import jetbrains.mps.generator.template.PropertyMacroContext;
import jetbrains.mps.generator.runtime.ApplySink;
import jetbrains.mps.generator.runtime.MetaObjectContainer;
import org.jetbrains.mps.openapi.language.SConcept;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import org.jetbrains.mps.openapi.language.SProperty;
import org.jetbrains.mps.openapi.language.SReferenceLink;
import org.jetbrains.mps.openapi.language.SContainmentLink;

@Generated
public class Template_reduce_PickMark extends TemplateDeclarationBase {

  public Template_reduce_PickMark() {
    super(new MO());
  }

  public SNodeReference getTemplateNode() {
    return new SNodePointer("r:262b93f0-fe86-497c-93c5-efd684d05bc6(jetbrains.mps.samples.KajaSceneConstruction.generator.template.main@generator)", "3210697320273614443");
  }


  protected FragmentResult applyPart0(@NotNull final TemplateContext context) throws GenerationException {
    final TemplateExecutionEnvironment environment = context.getEnvironment();
    final SNode tnode1 = environment.createOutputNode(myConcepts[0]);
    {
      TemplateContext context1 = context.subContext();
      {
        final SNode tnode2 = environment.createOutputNode(myConcepts[1]);
        {
          TemplateContext context2 = context1.subContext();
          {
            final SNode tnode3 = environment.createOutputNode(myConcepts[2]);
            {
              TemplateContext context3 = context2.subContext();
              {
                final SNode tnode4 = environment.createOutputNode(myConcepts[1]);
                {
                  TemplateContext context4 = context3.subContext();
                  {
                    final SNode tnode5 = environment.createOutputNode(myConcepts[2]);
                    {
                      TemplateContext context5 = context4.subContext();
                      {
                        final SNode tnode6 = environment.createOutputNode(myConcepts[3]);
                        {
                          environment.associate(tnode6, myAssociationLinks[0], "r:f5e9b11f-5073-4786-8ed1-a9e42307c3f8(JavaKaja.runtime)", "3210697320273614306");
                          TemplateContext context6 = context5.subContext();
                          {
                            final SNode tnode7 = environment.createOutputNode(myConcepts[4]);
                            SNodeAccessUtil.setPropertyValue(tnode7, myProperties[0], QueriesGenerated.propertyMacro_GetValue_4_0(new PropertyMacroContext(context6, "0", propertyMacro)));
                            environment.aggregate(tnode6, myAggregationLinks[0], tnode7);
                          }
                          {
                            final SNode tnode8 = environment.createOutputNode(myConcepts[4]);
                            SNodeAccessUtil.setPropertyValue(tnode8, myProperties[0], QueriesGenerated.propertyMacro_GetValue_4_1(new PropertyMacroContext(context6, "0", propertyMacro1)));
                            environment.aggregate(tnode6, myAggregationLinks[0], tnode8);
                          }
                        }
                        environment.aggregate(tnode5, myAggregationLinks[1], tnode6);
                      }
                      {
                        final SNode tnode9 = environment.createOutputNode(myConcepts[1]);
                        {
                          TemplateContext context7 = context5.subContext();
                          {
                            final SNode tnode10 = environment.createOutputNode(myConcepts[5]);
                            {
                              TemplateContext context8 = context7.subContext();
                              {
                                final SNode tnode11 = environment.createOutputNode(myConcepts[3]);
                                {
                                  environment.associate(tnode11, myAssociationLinks[0], "r:f5e9b11f-5073-4786-8ed1-a9e42307c3f8(JavaKaja.runtime)", "3210697320273550663");
                                  TemplateContext context9 = context8.subContext();
                                  {
                                    final SNode tnode12 = environment.createOutputNode(myConcepts[4]);
                                    SNodeAccessUtil.setPropertyValue(tnode12, myProperties[0], QueriesGenerated.propertyMacro_GetValue_4_2(new PropertyMacroContext(context9, "0", propertyMacro2)));
                                    environment.aggregate(tnode11, myAggregationLinks[0], tnode12);
                                  }
                                  {
                                    final SNode tnode13 = environment.createOutputNode(myConcepts[4]);
                                    SNodeAccessUtil.setPropertyValue(tnode13, myProperties[0], QueriesGenerated.propertyMacro_GetValue_4_3(new PropertyMacroContext(context9, "0", propertyMacro3)));
                                    environment.aggregate(tnode11, myAggregationLinks[0], tnode13);
                                  }
                                }
                                environment.aggregate(tnode10, myAggregationLinks[2], tnode11);
                              }
                            }
                            environment.aggregate(tnode9, myAggregationLinks[3], tnode10);
                          }
                          {
                            final SNode tnode14 = environment.createOutputNode(myConcepts[5]);
                            {
                              TemplateContext context10 = context7.subContext();
                              {
                                final SNode tnode15 = environment.createOutputNode(myConcepts[3]);
                                environment.associate(tnode15, myAssociationLinks[0], "r:f5e9b11f-5073-4786-8ed1-a9e42307c3f8(JavaKaja.runtime)", "3210697320273550615");
                                environment.aggregate(tnode14, myAggregationLinks[2], tnode15);
                              }
                            }
                            environment.aggregate(tnode9, myAggregationLinks[3], tnode14);
                          }
                        }
                        environment.aggregate(tnode5, myAggregationLinks[4], tnode9);
                      }
                      {
                        final SNode tnode16 = environment.createOutputNode(myConcepts[0]);
                        {
                          TemplateContext context11 = context5.subContext();
                          {
                            final SNode tnode17 = environment.createOutputNode(myConcepts[1]);
                            {
                              TemplateContext context12 = context11.subContext();
                              {
                                final SNode tnode18 = environment.createOutputNode(myConcepts[5]);
                                {
                                  TemplateContext context13 = context12.subContext();
                                  {
                                    final SNode tnode19 = environment.createOutputNode(myConcepts[3]);
                                    {
                                      environment.associate(tnode19, myAssociationLinks[0], "r:f5e9b11f-5073-4786-8ed1-a9e42307c3f8(JavaKaja.runtime)", "3308300503039580739");
                                      TemplateContext context14 = context13.subContext();
                                      {
                                        final SNode tnode20 = environment.createOutputNode(myConcepts[6]);
                                        tnode20.setProperty(myProperties[1], "Nothing to pick. The cell is empty.");
                                        environment.aggregate(tnode19, myAggregationLinks[0], tnode20);
                                      }
                                    }
                                    environment.aggregate(tnode18, myAggregationLinks[2], tnode19);
                                  }
                                }
                                environment.aggregate(tnode17, myAggregationLinks[3], tnode18);
                              }
                              {
                                final SNode tnode21 = environment.createOutputNode(myConcepts[7]);
                                environment.aggregate(tnode17, myAggregationLinks[3], tnode21);
                              }
                            }
                            environment.aggregate(tnode16, myAggregationLinks[5], tnode17);
                          }
                        }
                        environment.aggregate(tnode5, myAggregationLinks[6], tnode16);
                      }
                    }
                    environment.aggregate(tnode4, myAggregationLinks[3], tnode5);
                  }
                }
                environment.aggregate(tnode3, myAggregationLinks[4], tnode4);
              }
              {
                final SNode tnode22 = environment.createOutputNode(myConcepts[8]);
                {
                  TemplateContext context15 = context3.subContext();
                  {
                    final SNode tnode23 = environment.createOutputNode(myConcepts[3]);
                    {
                      environment.associate(tnode23, myAssociationLinks[0], "r:f5e9b11f-5073-4786-8ed1-a9e42307c3f8(JavaKaja.runtime)", "3210697320273648281");
                      TemplateContext context16 = context15.subContext();
                      {
                        final SNode tnode24 = environment.createOutputNode(myConcepts[4]);
                        SNodeAccessUtil.setPropertyValue(tnode24, myProperties[0], QueriesGenerated.propertyMacro_GetValue_4_4(new PropertyMacroContext(context16, "0", propertyMacro4)));
                        environment.aggregate(tnode23, myAggregationLinks[0], tnode24);
                      }
                    }
                    environment.aggregate(tnode22, myAggregationLinks[7], tnode23);
                  }
                  {
                    final SNode tnode25 = environment.createOutputNode(myConcepts[3]);
                    {
                      environment.associate(tnode25, myAssociationLinks[0], "r:f5e9b11f-5073-4786-8ed1-a9e42307c3f8(JavaKaja.runtime)", "3210697320273648203");
                      TemplateContext context17 = context15.subContext();
                      {
                        final SNode tnode26 = environment.createOutputNode(myConcepts[4]);
                        SNodeAccessUtil.setPropertyValue(tnode26, myProperties[0], QueriesGenerated.propertyMacro_GetValue_4_5(new PropertyMacroContext(context17, "0", propertyMacro5)));
                        environment.aggregate(tnode25, myAggregationLinks[0], tnode26);
                      }
                    }
                    environment.aggregate(tnode22, myAggregationLinks[8], tnode25);
                  }
                }
                environment.aggregate(tnode3, myAggregationLinks[1], tnode22);
              }
              {
                final SNode tnode27 = environment.createOutputNode(myConcepts[0]);
                {
                  TemplateContext context18 = context3.subContext();
                  {
                    final SNode tnode28 = environment.createOutputNode(myConcepts[1]);
                    {
                      TemplateContext context19 = context18.subContext();
                      {
                        final SNode tnode29 = environment.createOutputNode(myConcepts[5]);
                        {
                          TemplateContext context20 = context19.subContext();
                          {
                            final SNode tnode30 = environment.createOutputNode(myConcepts[3]);
                            {
                              environment.associate(tnode30, myAssociationLinks[0], "r:f5e9b11f-5073-4786-8ed1-a9e42307c3f8(JavaKaja.runtime)", "3308300503039580739");
                              TemplateContext context21 = context20.subContext();
                              {
                                final SNode tnode31 = environment.createOutputNode(myConcepts[6]);
                                tnode31.setProperty(myProperties[1], "Attempted to pick marks outside of the playground!");
                                environment.aggregate(tnode30, myAggregationLinks[0], tnode31);
                              }
                            }
                            environment.aggregate(tnode29, myAggregationLinks[2], tnode30);
                          }
                        }
                        environment.aggregate(tnode28, myAggregationLinks[3], tnode29);
                      }
                    }
                    environment.aggregate(tnode27, myAggregationLinks[5], tnode28);
                  }
                }
                environment.aggregate(tnode3, myAggregationLinks[6], tnode27);
              }
            }
            environment.aggregate(tnode2, myAggregationLinks[3], tnode3);
          }
          {
            final SNode tnode32 = environment.createOutputNode(myConcepts[9]);
            environment.aggregate(tnode2, myAggregationLinks[3], tnode32);
          }
        }
        environment.aggregate(tnode1, myAggregationLinks[5], tnode2);
      }
    }
    FragmentResult rv = nodeFragment(3, tnode1);
    return rv;
  }
  @Override
  public void apply(TemplateContext context, ApplySink sink) throws GenerationException {
    applyPart0(context).reportTo(sink);
  }

  /*package*/ static final class MO implements MetaObjectContainer {
    @Override
    public SConcept[] concepts() {
      SConcept[] rv = new SConcept[10];
      rv[0] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xfc092b6b77L, "BlockStatement");
      rv[1] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf8cc56b200L, "StatementList");
      rv[2] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf8cc56b217L, "IfStatement");
      rv[3] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0x6c6b6a1e379f9404L, "LocalMethodCall");
      rv[4] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf8cc59b314L, "IntegerConstant");
      rv[5] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf8cc56b213L, "ExpressionStatement");
      rv[6] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf93d565d10L, "StringLiteral");
      rv[7] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf8cc67c7feL, "ReturnStatement");
      rv[8] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xfb7c3070eeL, "AndExpression");
      rv[9] = MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf8cc56b215L, "Statement");
      return rv;
    }

    @Override
    public SProperty[] properties() {
      SProperty[] rv = new SProperty[2];
      rv[0] = MetaAdapterFactory.getProperty(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc59b314L, 0xf8cc59b315L, "value");
      rv[1] = MetaAdapterFactory.getProperty(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf93d565d10L, 0xf93d565d11L, "value");
      return rv;
    }

    @Override
    public SReferenceLink[] associations() {
      SReferenceLink[] rv = new SReferenceLink[1];
      rv[0] = MetaAdapterFactory.getReferenceLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x11857355952L, 0xf8c78301adL, "baseMethodDeclaration");
      return rv;
    }

    @Override
    public SContainmentLink[] aggregations() {
      SContainmentLink[] rv = new SContainmentLink[9];
      rv[0] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x11857355952L, 0xf8c78301aeL, "actualArgument");
      rv[1] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b217L, 0xf8cc56b218L, "condition");
      rv[2] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b213L, 0xf8cc56b214L, "expression");
      rv[3] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b200L, 0xf8cc6bf961L, "statement");
      rv[4] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b217L, 0xf8cc56b219L, "ifTrue");
      rv[5] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xfc092b6b77L, 0xfc092b6b78L, "statements");
      rv[6] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b217L, 0xfc092b6b76L, "ifFalseStatement");
      rv[7] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xfbdeb6fecfL, 0xfbdeb7a11bL, "rightExpression");
      rv[8] = MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xfbdeb6fecfL, 0xfbdeb7a11cL, "leftExpression");
      return rv;
    }
  }
  private static final SNodePointer propertyMacro = new SNodePointer("r:262b93f0-fe86-497c-93c5-efd684d05bc6(jetbrains.mps.samples.KajaSceneConstruction.generator.template.main@generator)", "3210697320273614490");
  private static final SNodePointer propertyMacro1 = new SNodePointer("r:262b93f0-fe86-497c-93c5-efd684d05bc6(jetbrains.mps.samples.KajaSceneConstruction.generator.template.main@generator)", "3210697320273614499");
  private static final SNodePointer propertyMacro2 = new SNodePointer("r:262b93f0-fe86-497c-93c5-efd684d05bc6(jetbrains.mps.samples.KajaSceneConstruction.generator.template.main@generator)", "3210697320273614510");
  private static final SNodePointer propertyMacro3 = new SNodePointer("r:262b93f0-fe86-497c-93c5-efd684d05bc6(jetbrains.mps.samples.KajaSceneConstruction.generator.template.main@generator)", "3210697320273614521");
  private static final SNodePointer propertyMacro4 = new SNodePointer("r:262b93f0-fe86-497c-93c5-efd684d05bc6(jetbrains.mps.samples.KajaSceneConstruction.generator.template.main@generator)", "3210697320273648469");
  private static final SNodePointer propertyMacro5 = new SNodePointer("r:262b93f0-fe86-497c-93c5-efd684d05bc6(jetbrains.mps.samples.KajaSceneConstruction.generator.template.main@generator)", "3210697320273648478");
}
