package jetbrains.mps.testbench.suite.editor;

/*Generated by MPS */

import jetbrains.mps.nodeEditor.menus.substitute.SubstituteMenuBase;
import jetbrains.mps.lang.editor.menus.EditorMenuDescriptorBase;
import jetbrains.mps.smodel.SNodePointer;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import jetbrains.mps.lang.editor.menus.MenuPart;
import jetbrains.mps.openapi.editor.menus.substitute.SubstituteMenuItem;
import jetbrains.mps.openapi.editor.menus.substitute.SubstituteMenuContext;
import java.util.ArrayList;
import jetbrains.mps.lang.editor.menus.substitute.ConstraintsFilteringSubstituteMenuPartDecorator;
import jetbrains.mps.lang.editor.menus.ParameterizedMenuPart;
import org.jetbrains.mps.openapi.module.SModuleReference;
import org.jetbrains.annotations.Nullable;
import jetbrains.mps.project.Solution;
import jetbrains.mps.smodel.ModuleRepositoryFacade;
import jetbrains.mps.internal.collections.runtime.Sequence;
import jetbrains.mps.lang.editor.menus.substitute.SingleItemSubstituteMenuPart;
import jetbrains.mps.lang.editor.menus.substitute.DefaultSubstituteMenuItem;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SConceptOperations;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations;
import jetbrains.mps.editor.runtime.completion.CompletionItemInformation;
import jetbrains.mps.smodel.runtime.IconResource;
import org.jetbrains.mps.openapi.language.SConcept;
import org.jetbrains.mps.openapi.language.SProperty;

public class SolutionRef_SubstituteMenu extends SubstituteMenuBase {
  public SolutionRef_SubstituteMenu() {
    super(false, new EditorMenuDescriptorBase("default substitute menu for " + "SolutionRef", new SNodePointer("r:aed1d11b-73e5-474f-a263-22833310a33f(jetbrains.mps.testbench.suite.editor)", "1741258697587114154")));
  }
  @NotNull
  @Override
  protected List<MenuPart<SubstituteMenuItem, SubstituteMenuContext>> getParts(final SubstituteMenuContext _context) {
    List<MenuPart<SubstituteMenuItem, SubstituteMenuContext>> result = new ArrayList<MenuPart<SubstituteMenuItem, SubstituteMenuContext>>();
    result.add(new ConstraintsFilteringSubstituteMenuPartDecorator(new SMP_Param_omknhr_a(), CONCEPTS.SolutionRef$_R));
    return result;
  }

  private class SMP_Param_omknhr_a extends ParameterizedMenuPart<SModuleReference, SubstituteMenuItem, SubstituteMenuContext> {
    /*package*/ SMP_Param_omknhr_a() {
      super(new EditorMenuDescriptorBase("parameterized substitute menu part", new SNodePointer("r:aed1d11b-73e5-474f-a263-22833310a33f(jetbrains.mps.testbench.suite.editor)", "1741258697587114156")));
    }
    @NotNull
    @Override
    protected List<SubstituteMenuItem> createItems(SModuleReference parameter, SubstituteMenuContext context) {
      return new SMP_Action_omknhr_a0(parameter).createItems(context);
    }
    @Nullable
    @Override
    protected Iterable<? extends SModuleReference> getParameters(SubstituteMenuContext _context) {
      Iterable<Solution> allSolutions = new ModuleRepositoryFacade(_context.getEditorContext().getRepository()).getAllModules(Solution.class);
      return Sequence.fromIterable(allSolutions).select((s) -> s.getModuleReference()).toList();
    }
    private class SMP_Action_omknhr_a0 extends SingleItemSubstituteMenuPart {
      private final SModuleReference myParameterObject;
      public SMP_Action_omknhr_a0(SModuleReference parameterObject) {
        myParameterObject = parameterObject;
      }

      @Nullable
      @Override
      protected SubstituteMenuItem createItem(SubstituteMenuContext _context) {
        Item item = new Item(_context);
        item.resetTraceInfo();
        return item;
      }
      private class Item extends DefaultSubstituteMenuItem {
        private final SubstituteMenuContext _context;
        public Item(SubstituteMenuContext context) {
          super(CONCEPTS.SolutionRef$_R, context);
          _context = context;
        }

        /*package*/ void resetTraceInfo() {
          String description = "Substitute item: " + getMatchingText("");
          description += ". Parameter object: " + myParameterObject;
          updateTraceInfo(description, new SNodePointer("r:aed1d11b-73e5-474f-a263-22833310a33f(jetbrains.mps.testbench.suite.editor)", "1741258697587114208"));
        }

        @Nullable
        @Override
        public SNode createNode(@NotNull String pattern) {
          SNode solutionRef = SConceptOperations.createNewNode(MetaAdapterFactory.getConcept(0xd3c5a46fb8c247dbL, 0xad0a30b8f19c2055L, 0x11c3fc56a6d1cbdcL, "jetbrains.mps.testbench.suite.structure.SolutionRef"));
          SPropertyOperations.assign(solutionRef, PROPS.moduleFQName$c3ZM, myParameterObject.getModuleName());
          SPropertyOperations.assign(solutionRef, PROPS.moduleID$c9a8, myParameterObject.getModuleId().toString());
          return solutionRef;
        }

        @NotNull
        protected CompletionItemInformation createInformation(String pattern) {
          return new CompletionItemInformation(myParameterObject, CONCEPTS.SolutionRef$_R, getMatchingText(pattern), getDescriptionText(pattern));
        }
        @Nullable
        @Override
        public String getDescriptionText(@NotNull String pattern) {
          return defaultDescriptionTextForParameter(myParameterObject, pattern);
        }
        @Nullable
        @Override
        public IconResource getIcon(@NotNull String pattern) {
          return defaultIconForParameter(myParameterObject, pattern);
        }
        @Nullable
        @Override
        public String getMatchingText(@NotNull String pattern) {
          return myParameterObject.getModuleName();
        }
      }
    }

  }

  private static final class CONCEPTS {
    /*package*/ static final SConcept SolutionRef$_R = MetaAdapterFactory.getConcept(0xd3c5a46fb8c247dbL, 0xad0a30b8f19c2055L, 0x11c3fc56a6d1cbdcL, "jetbrains.mps.testbench.suite.structure.SolutionRef");
  }

  private static final class PROPS {
    /*package*/ static final SProperty moduleFQName$c3ZM = MetaAdapterFactory.getProperty(0xd3c5a46fb8c247dbL, 0xad0a30b8f19c2055L, 0x11c3fc56a6d1cbdcL, 0x11c3fc56a6d1cbddL, "moduleFQName");
    /*package*/ static final SProperty moduleID$c9a8 = MetaAdapterFactory.getProperty(0xd3c5a46fb8c247dbL, 0xad0a30b8f19c2055L, 0x11c3fc56a6d1cbdcL, 0x11c3fc56a6d1cbdeL, "moduleID");
  }
}
