// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.plugins.javaFX.fxml;

import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.openapi.application.PluginPathManager;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.javaFX.fxml.codeInsight.inspections.JavaFxEventHandlerInspection;

public class JavaFxEventHandlerInspectionTest extends AbstractJavaFXTestCase {

  @Override
  protected void enableInspections() {
    myFixture.enableInspections(new JavaFxEventHandlerInspection());
  }


  public void testHighlightExact() {
    doHighlightingTest();
  }

  public void testHighlightNonVoid() {
    final JavaFxEventHandlerInspection inspection = new JavaFxEventHandlerInspection();
    inspection.myDetectNonVoidReturnType = true;
    myFixture.enableInspections(inspection);
    doHighlightingTest();
  }

  public void testHighlightAmbiguous() {
    doHighlightingTest();
  }

  public void testHighlightGeneric() {
    doHighlightingTest();
  }

  public void testHighlightRaw() {
    doHighlightingTest();
  }

  public void testHighlightHalfRaw() {
    doHighlightingTest();
  }

  public void testHighlightSpecific() {
    doHighlightingTest();
  }

  public void testHighlightSuper() {
    doHighlightingTest();
  }

  public void testHighlightWildcard() {
    doHighlightingTest();
  }

  public void testQuickfixRaw() {
    doQuickfixTest("Create method 'onSort'");
  }

  public void testQuickfixHalfRaw() {
    doQuickfixTest("Create method 'onSort'");
  }

  public void testQuickfixSpecific() {
    doQuickfixTest("Create method 'onSort'");
  }

  public void testQuickfixNoField() {
    doQuickfixTest("Create method 'onSort'");
  }

  public void testQuickfixFieldType() {
    doQuickfixTest("Change field 'table' type to 'TableView<Map<String, Double>>'");
  }

  public void testQuickfixNoFieldNested() {
    final JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject());
    settings.INSERT_INNER_CLASS_IMPORTS = true;
    doQuickfixTest("Create method 'onColumnEditStart'");
  }

  public void testQuickfixSuper() {
    doQuickfixTest("Create method 'click'");
  }

  private void doHighlightingTest() {
    myFixture.configureByFiles(getTestName(true) + ".fxml", getTestName(false) + ".java");
    myFixture.checkHighlighting();
  }

  private void doQuickfixTest(final String actionName) {
    String path = getTestName(true) + ".fxml";
    myFixture.configureByFiles(path, getTestName(false) + ".java");
    IntentionAction intention = myFixture.findSingleIntention(actionName);
    assertNotNull(intention);
    myFixture.launchAction(intention);
    myFixture.checkResultByFile(getTestName(false) + ".java", getTestName(false) + "_after.java", true);
  }

  @NotNull
  @Override
  protected String getTestDataPath() {
    return PluginPathManager.getPluginHomePath("javaFX") + "/testData/inspections/eventHandler/";
  }
}
