// Copyright 2000-2018 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 com.intellij.openapi.application;

import com.intellij.ide.ApplicationInitializedListener;
import com.intellij.internal.statistic.eventLog.FeatureUsageData;
import com.intellij.internal.statistic.service.fus.collectors.FUCounterUsageLogger;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;

public class ImportOldConfigsUsagesCollector  {
  public static class Trigger implements ApplicationInitializedListener {
    @Override
    public void componentsInitialized() {
      final ImportOldConfigsState state = ImportOldConfigsState.getInstance();
      if (state.isOldConfigPanelWasOpened()) {
        final FeatureUsageData data = new FeatureUsageData().
          addData("selected", state.getType().name()).
          addData("config_folder_exists", state.isSourceConfigFolderExists());
        FUCounterUsageLogger.getInstance().logEvent("import.old.config", "import.dialog.shown", data);
      }
    }
  }

  public static class ImportOldConfigsState {
    private static final ImportOldConfigsState ourInstance = new ImportOldConfigsState();

    public static ImportOldConfigsState getInstance() {
      return ourInstance;
    }

    private volatile boolean myOldConfigPanelWasOpened = false;
    private volatile boolean mySourceConfigFolderExists = false;
    @NotNull
    private volatile ImportOldConfigType myType = ImportOldConfigType.NOT_INITIALIZED;

    public void saveImportOldConfigType(@NotNull JRadioButton previous,
                                        @NotNull JRadioButton custom,
                                        @NotNull JRadioButton doNotImport,
                                        boolean configFolderExists) {
      myOldConfigPanelWasOpened = true;
      mySourceConfigFolderExists = configFolderExists;
      myType = getOldImportType(previous, custom, doNotImport);
    }

    @NotNull
    private static ImportOldConfigType getOldImportType(@NotNull JRadioButton previous,
                                                        @NotNull JRadioButton custom,
                                                        @NotNull JRadioButton doNotImport) {
      if (previous.isSelected()) return ImportOldConfigType.FROM_PREVIOUS;
      if (custom.isSelected()) return ImportOldConfigType.FROM_CUSTOM;
      if (doNotImport.isSelected()) return ImportOldConfigType.DO_NOT_IMPORT;
      return ImportOldConfigType.OTHER;
    }


    public boolean isOldConfigPanelWasOpened() {
      return myOldConfigPanelWasOpened;
    }

    public boolean isSourceConfigFolderExists() {
      return mySourceConfigFolderExists;
    }

    @NotNull
    public ImportOldConfigType getType() {
      return myType;
    }
  }

  public enum ImportOldConfigType {
    FROM_PREVIOUS, FROM_CUSTOM, DO_NOT_IMPORT, OTHER, NOT_INITIALIZED
  }
}
@@ -17,10 +17,10 @@
 0-20
-18
+20
  Jet
@@ -229,24 +229,87 @@
 edListener;%0A
+import com.intellij.internal.statistic.eventLog.EventLogGroup;%0A
 import com.i
@@ -405,166 +405,914 @@
 tic.
-service.fus.collectors.FUCounterUsageLogger;%0Aimport org.jetbrains.annotations.NotNull;%0A%0Aimport javax.swing.*;%0A%0Apublic class ImportOldConfigsUsagesCollector  %7B
+eventLog.events.EnumEventField;%0Aimport com.intellij.internal.statistic.eventLog.events.EventFields;%0Aimport com.intellij.internal.statistic.eventLog.events.EventId;%0Aimport com.intellij.internal.statistic.eventLog.events.EventId2;%0Aimport com.intellij.internal.statistic.service.fus.collectors.FUCounterUsageLogger;%0Aimport org.jetbrains.annotations.NotNull;%0A%0Aimport javax.swing.*;%0A%0Aimport static com.intellij.internal.statistic.eventLog.events.EventFields.Boolean;%0Aimport static com.intellij.internal.statistic.eventLog.events.EventFields.Enum;%0A%0Apublic class ImportOldConfigsUsagesCollector %7B%0A  private static final EventLogGroup EVENT_GROUP = new EventLogGroup(%22import.old.config%22, 1);%0A  private static final EventId2%3CImportOldConfigType, Boolean%3E IMPORT_DIALOG_SHOWN_EVENT =%0A    EVENT_GROUP.registerEvent(%22import.dialog.shown%22, Enum(%22selected%22, ImportOldConfigType.class), Boolean(%22config_folder_exists%22));%0A
 %0A  p
@@ -1444,22 +1444,16 @@
 %7B%0A      
-final 
 ImportOl
@@ -1570,296 +1570,89 @@
     
-final FeatureUsageData data = new FeatureUsageData().%0A          addData(%22selected%22, state.getType().name()).%0A          addData(%22config_folder_exists%22, state.isSourceConfigFolderExists());%0A        FUCounterUsageLogger.getInstance().logEvent(%22import.old.config%22, %22import.dialog.shown%22, data
+IMPORT_DIALOG_SHOWN_EVENT.log(state.getType(), state.isSourceConfigFolderExists()
 );%0A 

rewrite ImportOldConfigsUsagesCollector to new fus API