package com.atlassian.bitbucket.mesh.git.gc;

import com.atlassian.bitbucket.mesh.config.GcConfig;
import com.atlassian.bitbucket.mesh.repository.Repository;

import javax.annotation.Nonnull;

/**
 * Scheduler to be used by {@link GcOperation} implementations to schedule chained garbage collection operations and
 * apply the standard error handling to the chained operations.
 */
interface GcOperationScheduler {

    /**
     * Schedules the provided {@code operation} to run immediately if it {@link GcOperation#shouldRun() should run}.
     *
     * @param repository the repository
     * @param operation the operation to run
     */
    void maybeRun(@Nonnull Repository repository, @Nonnull GcOperation operation);

    /**
     * Schedules the provided {@code operation} to run with the {@link GcConfig#getDelay() standard delay} if
     * it {@link GcOperation#shouldRun() should run}.
     *
     * @param repository the repository
     * @param operation the operation to run
     */
    void maybeSchedule(@Nonnull Repository repository, @Nonnull GcOperation operation);

    /**
     * Schedules the provided {@code operation} to run with the {@link GcConfig#getDelay() standard delay} +
     * {@code extraDelaySeconds} if it {@link GcOperation#shouldRun() should run}.
     *
     * @param repository the repository
     * @param operation the operation to run
     * @param extraDelaySeconds the extra delay (compared to the standard delay) to apply
     */
    void maybeSchedule(@Nonnull Repository repository, @Nonnull GcOperation operation, long extraDelaySeconds);
}
