// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInspection.javaDoc;

import com.intellij.java.JavaBundle;
import com.intellij.modcommand.ModPsiUpdater;
import com.intellij.modcommand.PsiUpdateModCommandQuickFix;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.javadoc.PsiDocTag;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NotNull;

class RemoveTagFix extends PsiUpdateModCommandQuickFix {
  private final String myTagName;
  private final String myParamName;

  RemoveTagFix(String tagName) {
    myTagName = tagName;
    myParamName = null;
  }

  RemoveTagFix(String tagName, String paramName) {
    myTagName = tagName;
    myParamName = paramName;
  }

  @Override
  public @NotNull String getName() {
    return myParamName == null 
           ? JavaBundle.message("quickfix.text.remove.javadoc.0", myTagName)
           : JavaBundle.message("quickfix.text.remove.javadoc.0.1", myTagName, myParamName);
  }

  @Override
  public @NotNull String getFamilyName() {
    return JavaBundle.message("quickfix.family.remove.javadoc.tag");
  }

  @Override
  protected void applyFix(@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) {
    PsiDocTag tag = PsiTreeUtil.getParentOfType(element, PsiDocTag.class);
    if (tag != null) {
      tag.delete();
    }
  }
}
