package com.atlassian.stash.internal.license;

import com.atlassian.bitbucket.i18n.KeyedMessage;

import javax.annotation.Nonnull;
import java.util.Optional;

/**
 * Handler for the grace period for when the license limit is exceeded
 *
 * @since 4.8
 */
public interface GracePeriodHandler {

    /**
     * Determine whether we are in the grace period or not.
     *
     * @return {@code true} if the system is the grace period, {@code false} otherwise.
     */
    boolean isActive();

    /**
     * Get the grace period message.
     *
     * @return the message describing how much time remains of the grace period, or {@link Optional#empty()} if not in
     * the grace period.
     */
    @Nonnull
    Optional<KeyedMessage> getMessage();

    /**
     * Retrieve the start time of the grace period.
     *
     * @return the start time grace period in milliseconds, or {@link Optional#empty()} if not in the grace period.
     */
    @Nonnull
    Optional<Long> getStartTime();

    /**
     * Starts the grace period. If the grace period is already started, this method does nothing.
     */
    void start();

    /**
     * Stop the license grace period.
     * <p>
     * Stopping the grace period after it has expired resets the grace period for the next time the license is exceeded.
     */
    void stop();
}
