package jetbrains.mps.build.typesystem;

/*Generated by MPS */

import jetbrains.mps.errors.QuickFix_Runtime;
import jetbrains.mps.smodel.SNodePointer;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.internal.collections.runtime.Sequence;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations;
import java.util.Objects;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations;
import jetbrains.mps.smodel.builder.SNodeBuilder;
import org.jetbrains.mps.openapi.language.SContainmentLink;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import org.jetbrains.mps.openapi.language.SReferenceLink;
import org.jetbrains.mps.openapi.language.SConcept;
import org.jetbrains.mps.openapi.language.SProperty;

public class declareKotlincHomeFromMpsHome_QuickFix extends QuickFix_Runtime {
  public declareKotlincHomeFromMpsHome_QuickFix() {
    super(new SNodePointer("r:2349e4dd-6518-4a4c-9022-c7887bed8b52(jetbrains.mps.build.typesystem)", "4427790052271506383"));
  }
  public String getDescription(SNode node) {
    return "Define macro $" + KotlincMacroHelper.KOTLINC_HOME + " with default $" + KotlincMacroHelper.MPS_HOME + "/plugins/mps-kotlin/kotlinc";
  }
  public void execute(SNode node) {
    // Search for $mps_home or define it
    SNode from = Sequence.fromIterable(SNodeOperations.ofConcept(SLinkOperations.getChildren(((SNode) declareKotlincHomeFromMpsHome_QuickFix.this.getField("project")[0]), LINKS.macros$r8_A), CONCEPTS.BuildFolderMacro$mR)).findFirst((it) -> Objects.equals(SPropertyOperations.getString(it, PROPS.name$MnvL), KotlincMacroHelper.MPS_HOME));
    if ((from == null)) {
      from = SLinkOperations.addNewChild(((SNode) declareKotlincHomeFromMpsHome_QuickFix.this.getField("project")[0]), LINKS.macros$r8_A, CONCEPTS.BuildFolderMacro$mR);
      SPropertyOperations.assign(from, PROPS.name$MnvL, KotlincMacroHelper.MPS_HOME);
    }


    SNode newMacro = SLinkOperations.addNewChild(((SNode) declareKotlincHomeFromMpsHome_QuickFix.this.getField("project")[0]), LINKS.macros$r8_A, CONCEPTS.BuildFolderMacro$mR);
    SPropertyOperations.assign(newMacro, PROPS.name$MnvL, KotlincMacroHelper.KOTLINC_HOME);
    SLinkOperations.setTarget(newMacro, LINKS.defaultPath$9tbQ, createBuildSourceMacroRelativePath_l69670_a0h0c(from));
  }
  private static SNode createBuildSourceMacroRelativePath_l69670_a0h0c(SNode p0) {
    SNodeBuilder n0 = new SNodeBuilder().init(CONCEPTS.BuildSourceMacroRelativePath$b7);
    n0.setReferenceTarget(LINKS.macro$kdvp, p0);
    {
      SNodeBuilder n1 = n0.forChild(LINKS.compositePart$blMW).init(CONCEPTS.BuildCompositePath$Eh);
      n1.setProperty(PROPS.head$$gC$, "plugins");
      {
        SNodeBuilder n2 = n1.forChild(LINKS.tail$$gpz).init(CONCEPTS.BuildCompositePath$Eh);
        n2.setProperty(PROPS.head$$gC$, "mps-kotlin");
        {
          SNodeBuilder n3 = n2.forChild(LINKS.tail$$gpz).init(CONCEPTS.BuildCompositePath$Eh);
          n3.setProperty(PROPS.head$$gC$, "kotlinc");
        }
      }
    }
    return n0.getResult();
  }

  private static final class LINKS {
    /*package*/ static final SContainmentLink macros$r8_A = MetaAdapterFactory.getContainmentLink(0x798100da4f0a421aL, 0xb99171f8c50ce5d2L, 0x4df58c6f18f84a13L, 0x4df58c6f18f84a22L, "macros");
    /*package*/ static final SContainmentLink defaultPath$9tbQ = MetaAdapterFactory.getContainmentLink(0x798100da4f0a421aL, 0xb99171f8c50ce5d2L, 0x668c6cfbafadd002L, 0x668c6cfbafadf0eaL, "defaultPath");
    /*package*/ static final SReferenceLink macro$kdvp = MetaAdapterFactory.getReferenceLink(0x798100da4f0a421aL, 0xb99171f8c50ce5d2L, 0x668c6cfbafae121dL, 0x668c6cfbafae122aL, "macro");
    /*package*/ static final SContainmentLink compositePart$blMW = MetaAdapterFactory.getContainmentLink(0x798100da4f0a421aL, 0xb99171f8c50ce5d2L, 0x65997a657729f6fbL, 0x65997a65772aebcbL, "compositePart");
    /*package*/ static final SContainmentLink tail$$gpz = MetaAdapterFactory.getContainmentLink(0x798100da4f0a421aL, 0xb99171f8c50ce5d2L, 0x779c6e65c01467f1L, 0x779c6e65c01467f2L, "tail");
  }

  private static final class CONCEPTS {
    /*package*/ static final SConcept BuildFolderMacro$mR = MetaAdapterFactory.getConcept(0x798100da4f0a421aL, 0xb99171f8c50ce5d2L, 0x668c6cfbafadd002L, "jetbrains.mps.build.structure.BuildFolderMacro");
    /*package*/ static final SConcept BuildSourceMacroRelativePath$b7 = MetaAdapterFactory.getConcept(0x798100da4f0a421aL, 0xb99171f8c50ce5d2L, 0x668c6cfbafae121dL, "jetbrains.mps.build.structure.BuildSourceMacroRelativePath");
    /*package*/ static final SConcept BuildCompositePath$Eh = MetaAdapterFactory.getConcept(0x798100da4f0a421aL, 0xb99171f8c50ce5d2L, 0x779c6e65c01467f1L, "jetbrains.mps.build.structure.BuildCompositePath");
  }

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