package com.atlassian.stash.internal.mail;

import com.atlassian.bitbucket.mail.MailMessage;

import javax.annotation.Nonnull;

/**
 * Guard to limit the size of a mail queue.
 *
 * @since 2.0
 */
public interface MailQueueSizeGuard {

    /**
     * Reserves the size of an email in the queue.
     *
     * @throws InsufficientSpaceOnMailQueueException if the size of the email exceeds the space left on the mail queue
     */
    @Nonnull
    Claim claimSpace(@Nonnull MailMessage mail) throws InsufficientSpaceOnMailQueueException;

    /**
     * Gets the sum of all the reservations.
     */
    int getReservedSize();

    /**
     * A reservation on the mail queue.
     */
    public interface Claim {
        void release();
    }
}
