package jetbrains.mps.lang.core.scripts;

/*Generated by MPS */

import jetbrains.mps.lang.script.runtime.BaseMigrationScript;
import jetbrains.mps.lang.script.runtime.AbstractMigrationRefactoring;
import org.jetbrains.mps.openapi.language.SAbstractConcept;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.internal.collections.runtime.ListSequence;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SConceptOperations;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import java.util.Objects;
import jetbrains.mps.lang.core.behavior.PropertyAttribute__BehaviorDescriptor;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.mps.openapi.model.SNodeReference;
import org.jetbrains.mps.openapi.persistence.PersistenceFacade;
import org.jetbrains.mps.openapi.language.SConcept;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import org.jetbrains.mps.openapi.language.SProperty;

public final class MigrateEnumPropertyAttributes_MigrationScript extends BaseMigrationScript {
  public MigrateEnumPropertyAttributes_MigrationScript() {
    super("Manual migration for enum property attributes");
    this.addRefactoring(new AbstractMigrationRefactoring() {
      @Override
      public String getName() {
        return "Migrate by hand (some type errors have to be fixed manually)";
      }
      @Override
      public String getAdditionalInfo() {
        return "Migrate by hand (some type errors have to be fixed manually)";
      }
      @Override
      public SAbstractConcept getApplicableConcept() {
        return CONCEPTS.PropertyAttribute$Gb;
      }
      @Override
      public boolean isApplicableInstanceNode(SNode node) {
        if (ListSequence.fromList(SConceptOperations.getAllSuperConcepts(SNodeOperations.getConcept(node), false)).any((it) -> Objects.equals(it.getName(), "StringToTypedValueMigrationInfo"))) {
          // property will take care for providing the intention
          return false;
        }
        return SNodeOperations.isInstanceOf(SNodeOperations.getParent(PropertyAttribute__BehaviorDescriptor.getPropertyDeclaration_id121FNPYBLc9.invoke(node)), CONCEPTS.EnumPropertyMigrationInfo$O3);
      }
      @Override
      public void doUpdateInstanceNode(SNode node) {
        SPropertyOperations.assign(node, PROPS.enumUsageMigrated$64YW, true);
      }
      @Override
      public boolean isShowAsIntention() {
        return true;
      }
    });
  }

  @Nullable
  @Override
  public SNodeReference getScriptNode() {
    return PersistenceFacade.getInstance().createNodeReference("r:a835f613-568f-4856-9519-c3f6c0c635e5(jetbrains.mps.lang.core.scripts)/979583239732302831");
  }

  private static final class CONCEPTS {
    /*package*/ static final SConcept PropertyAttribute$Gb = MetaAdapterFactory.getConcept(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x2eb1ad060897da56L, "jetbrains.mps.lang.core.structure.PropertyAttribute");
    /*package*/ static final SConcept EnumPropertyMigrationInfo$O3 = MetaAdapterFactory.getConcept(0xc72da2b97cce4447L, 0x8389f407dc1158b7L, 0x5a14f1035942a5abL, "jetbrains.mps.lang.structure.structure.EnumPropertyMigrationInfo");
  }

  private static final class PROPS {
    /*package*/ static final SProperty enumUsageMigrated$64YW = MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x2eb1ad060897da56L, 0x1081af3d7e9d6a2fL, "enumUsageMigrated");
  }
}
