package jetbrains.mps.lang.test.migration;

/*Generated by MPS */

import jetbrains.mps.lang.migration.runtime.base.MigrationScriptBase;
import org.jetbrains.mps.openapi.model.SNode;
import org.jetbrains.mps.openapi.module.SModule;
import org.jetbrains.mps.openapi.module.SearchScope;
import jetbrains.mps.lang.smodel.query.runtime.CommandUtil;
import jetbrains.mps.project.EditableFilteringScope;
import jetbrains.mps.lang.smodel.query.runtime.QueryExecutionContext;
import jetbrains.mps.internal.collections.runtime.CollectionSequence;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations;
import jetbrains.mps.internal.collections.runtime.ListSequence;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations;
import jetbrains.mps.lang.migration.runtime.base.Problem;
import jetbrains.mps.baseLanguage.closures.runtime._FunctionTypes;
import jetbrains.mps.lang.migration.runtime.base.DeprecatedConceptMemberNotMigratedProblem;
import jetbrains.mps.lang.migration.runtime.base.MigrationScriptReference;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import jetbrains.mps.smodel.builder.SNodeBuilder;
import org.jetbrains.mps.openapi.language.SConcept;
import org.jetbrains.mps.openapi.language.SReferenceLink;
import org.jetbrains.mps.openapi.language.SContainmentLink;
import org.jetbrains.mps.openapi.language.SProperty;

public class MigrationTestCase_migration extends MigrationScriptBase {
  private final String description = "MigrationTestCase";
  public String getCaption() {
    return description;
  }
  @Override
  public boolean isRerunnable() {
    return true;
  }
  public SNode execute(final SModule m) {
    doExecute(m);
    return null;
  }
  public void doExecute(final SModule m) {
    {
      SearchScope scope_y0ige7_a0e = CommandUtil.createScope(m);
      final SearchScope scope_y0ige7_a0e_0 = new EditableFilteringScope(scope_y0ige7_a0e);
      QueryExecutionContext context = () -> scope_y0ige7_a0e_0;
      CollectionSequence.fromCollection(CommandUtil.instances(CommandUtil.selectScope(null, context), CONCEPTS.MigrationTestCase$7Q, true)).where((it) -> (SLinkOperations.getTarget(it, LINKS.migration_old$IR61) != null)).visitAll((it) -> {
        ListSequence.fromList(SLinkOperations.getChildren(it, LINKS.migration$BNbu)).addElement(createMigrationReference_y0ige7_a0a0a0a0a0a0d(SLinkOperations.getTarget(it, LINKS.migration_old$IR61)));
        SPropertyOperations.assign(it, PROPS.name$MnvL, SPropertyOperations.getString(SLinkOperations.getTarget(it, LINKS.migration_old$IR61), PROPS.name$MnvL) + "_Test");
        SLinkOperations.setTarget(it, LINKS.migration_old$IR61, null);
      });
    }
  }
  @Override
  public Iterable<Problem> check(SModule m) {
    {
      SearchScope scope_y0ige7_a0f = CommandUtil.createScope(m);
      final SearchScope scope_y0ige7_a0f_0 = new EditableFilteringScope(scope_y0ige7_a0f);
      QueryExecutionContext context = () -> scope_y0ige7_a0f_0;
      return CollectionSequence.fromCollection(CommandUtil.instances(CommandUtil.selectScope(null, context), CONCEPTS.MigrationTestCase$7Q, true)).where((it) -> (SLinkOperations.getTarget(it, LINKS.migration_old$IR61) != null)).select(new _FunctionTypes._return_P1_E0<Problem, SNode>() {
        public Problem invoke(SNode it) {
          return DeprecatedConceptMemberNotMigratedProblem.deprecatedReferenceLink(it, LINKS.migration_old$IR61);
        }
      });
    }
  }
  public MigrationScriptReference getReference() {
    return new MigrationScriptReference(MetaAdapterFactory.getLanguage(0x8585453e6bfb4d80L, 0x98deb16074f1d86cL, "jetbrains.mps.lang.test"), 1);
  }


  private static SNode createMigrationReference_y0ige7_a0a0a0a0a0a0d(SNode p0) {
    SNodeBuilder n0 = new SNodeBuilder().init(CONCEPTS.MigrationReference$R6);
    n0.setReferenceTarget(LINKS.migration$XW2Z, p0);
    return n0.getResult();
  }

  private static final class CONCEPTS {
    /*package*/ static final SConcept MigrationTestCase$7Q = MetaAdapterFactory.getConcept(0x8585453e6bfb4d80L, 0x98deb16074f1d86cL, 0x4c010b30d9be4be7L, "jetbrains.mps.lang.test.structure.MigrationTestCase");
    /*package*/ static final SConcept MigrationReference$R6 = MetaAdapterFactory.getConcept(0x8585453e6bfb4d80L, 0x98deb16074f1d86cL, 0x5bf7864595dddf89L, "jetbrains.mps.lang.test.structure.MigrationReference");
  }

  private static final class LINKS {
    /*package*/ static final SReferenceLink migration_old$IR61 = MetaAdapterFactory.getReferenceLink(0x8585453e6bfb4d80L, 0x98deb16074f1d86cL, 0x4c010b30d9be4be7L, 0x4c010b30d9be54a3L, "migration_old");
    /*package*/ static final SContainmentLink migration$BNbu = MetaAdapterFactory.getContainmentLink(0x8585453e6bfb4d80L, 0x98deb16074f1d86cL, 0x4c010b30d9be4be7L, 0x5bf7864595df8b02L, "migration");
    /*package*/ static final SReferenceLink migration$XW2Z = MetaAdapterFactory.getReferenceLink(0x8585453e6bfb4d80L, 0x98deb16074f1d86cL, 0x5bf7864595dddf89L, 0x5bf7864595dddf8aL, "migration");
  }

  private static final class PROPS {
    /*package*/ static final SProperty name$MnvL = MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x110396eaaa4L, 0x110396ec041L, "name");
  }
}
