package com.adobe.aem.modernize.policy;

/*-
 * #%L
 * AEM Modernize Tools - Core
 * %%
 * Copyright (C) 2019 - 2021 Adobe Inc.
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import java.util.Set;
import javax.jcr.Node;
import javax.jcr.RepositoryException;

import com.adobe.aem.modernize.RewriteException;
import com.adobe.aem.modernize.rule.ServiceBasedRewriteRule;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.osgi.annotation.versioning.ConsumerType;

/**
 * Interface for services that implement a Design rewrite rule.
 */
@ConsumerType
public interface PolicyImportRule extends ServiceBasedRewriteRule {

  /**
   * <p>Applies this rule to the subtree rooted at the specified <code>root</code> node.
   *
   * Implementations create a new Node to return, leaving original intact. All other rules of {@link com.adobe.aem.modernize.rule.RewriteRule#applyTo} should be adhered to.
   *
   * @param root The root of the subtree to be rewritten
   * @param finalPaths list of nodes paths which should not be updated after this method completes
   * @return the root node of the rewritten tree, or null if it was removed
   * @throws RewriteException if the rewrite operation failed or cannot be completed
   * @throws RepositoryException if the node updates cannot be saved
   */
  @Nullable
  @Override
  Node applyTo(@NotNull Node root, @NotNull Set<String> finalPaths) throws RewriteException, RepositoryException;
}
