package com.atlassian.stash.internal.pull.rescope;

import com.atlassian.stash.internal.repository.InternalRepository;
import com.atlassian.stash.internal.user.InternalApplicationUser;

import javax.annotation.Nonnull;
import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * @since 4.9
 */
public interface PullRequestRescopeScheduler {
    /**
     * Creates a rescope request for the provided repository that forces rescoping to consider all open pull requests
     * from / to a branch in that repository. Any pull request that is found to be out of date will be updated. If the
     * change to the branch in question cannot be explained by other rescope requests, the change and corresponding
     * rescope activity will be attributed to the provided {@code user} and {@code triggerDate}
     *
     * @param repository the repository to rescope
     * @param user the user to attribute unexplained ref changes to
     * @param triggerDate the date to use as the rescope date on rescope activities
     * @param delay the processing delay
     * @param timeUnit the delay's timeUnit
     */
    void forceRescope(@Nonnull InternalRepository repository, @Nonnull InternalApplicationUser user,
                      @Nonnull Date triggerDate, long delay, @Nonnull TimeUnit timeUnit);

    /**
     * Triggers a rescope of a repository, only considering open pull request for which rescope requests exist. If no
     * rescope requests exist in the database, no pull requests will be rescoped.
     *
     * @param repository the repository to rescope
     * @param delay the processing delay
     * @param timeUnit the delay's timeUnit
     */
    void triggerRescope(@Nonnull InternalRepository repository, long delay, @Nonnull TimeUnit timeUnit);
}
