// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.idea.devkit;

import com.intellij.icons.AllIcons;
import com.intellij.ide.fileTemplates.FileTemplateDescriptor;
import com.intellij.ide.fileTemplates.FileTemplateGroupDescriptor;
import com.intellij.ide.fileTemplates.FileTemplateGroupDescriptorFactory;
import com.intellij.ide.highlighter.HtmlFileType;
import com.intellij.ide.highlighter.JavaFileType;
import com.intellij.ide.highlighter.XmlFileType;
import org.jetbrains.annotations.NotNull;

public final class DevKitFileTemplatesFactory implements FileTemplateGroupDescriptorFactory {

  public static final String PLUGIN_XML = "devkit-plugin.xml";
  public static final String THEME_PLUGIN_XML = "devkit-theme-plugin.xml";
  public static final String THEME_JSON = "devkit-theme.json";
  public static final String BUILD_GRADLE_KTS = "devkit-build.gradle.kts";
  public static final String SETTINGS_GRADLE_KTS = "devkit-settings.gradle.kts";
  public static final String GRADLE_WRAPPER_PROPERTIES = "devkit-gradle-wrapper.properties";
  public static final String GRADLE_PROPERTIES = "devkit-gradle.properties";

  public static final String TOOLWINDOW_EXAMPLE_KT = "devkit-MyToolWindow.kt";
  public static final String TOOLWINDOW_COMPOSE_EXAMPLE_KT = "devkit-compose-MyToolWindow.kt";
  public static final String MESSAGE_BUNDLE_EXAMPLE_PROPERTIES = "devkit-MyMessageBundle.properties";
  public static final String MESSAGE_BUNDLE_EXAMPLE_KT = "devkit-MyMessageBundle.kt";

  @Override
  public FileTemplateGroupDescriptor getFileTemplatesDescriptor() {
    FileTemplateGroupDescriptor root = new FileTemplateGroupDescriptor(DevKitBundle.message("module.builder.title"), AllIcons.Nodes.Plugin);
    FileTemplateGroupDescriptor templatesRoot =
      new FileTemplateGroupDescriptor(DevKitBundle.message("file.templates"), AllIcons.Nodes.Plugin);

    templatesRoot.addTemplate(new FileTemplateDescriptor("gradleBasedPlugin.xml", XmlFileType.INSTANCE.getIcon()) {
      @Override
      public @NotNull String getDisplayName() {
        return DevKitBundle.message("module.wizard.gradle.plugin.xml.template.display.name");
      }
    });
    templatesRoot.addTemplate(new FileTemplateDescriptor("plugin.xml", XmlFileType.INSTANCE.getIcon()));
    templatesRoot.addTemplate(new FileTemplateDescriptor("Action.java", JavaFileType.INSTANCE.getIcon()));
    templatesRoot.addTemplate(new FileTemplateDescriptor("InspectionDescription.html", HtmlFileType.INSTANCE.getIcon()));

    FileTemplateGroupDescriptor newProjectRoot =
      new FileTemplateGroupDescriptor(DevKitBundle.message("file.templates.new.plugin"), AllIcons.Nodes.Plugin);

    newProjectRoot.addTemplate(PLUGIN_XML);
    newProjectRoot.addTemplate(THEME_PLUGIN_XML);
    newProjectRoot.addTemplate(THEME_JSON);
    newProjectRoot.addTemplate(BUILD_GRADLE_KTS);
    newProjectRoot.addTemplate(SETTINGS_GRADLE_KTS);
    newProjectRoot.addTemplate(GRADLE_WRAPPER_PROPERTIES);
    newProjectRoot.addTemplate(GRADLE_PROPERTIES);

    newProjectRoot.addTemplate(TOOLWINDOW_EXAMPLE_KT);
    newProjectRoot.addTemplate(TOOLWINDOW_COMPOSE_EXAMPLE_KT);
    newProjectRoot.addTemplate(MESSAGE_BUNDLE_EXAMPLE_PROPERTIES);
    newProjectRoot.addTemplate(MESSAGE_BUNDLE_EXAMPLE_KT);

    root.addTemplate(templatesRoot);
    root.addTemplate(newProjectRoot);

    return root;
  }
}
