package com.atlassian.bitbucket.mesh.config;

import com.atlassian.bitbucket.mesh.annotation.ManagedByControlPlane;

import javax.annotation.Nonnull;
import java.nio.file.Path;
import java.time.Duration;

public interface PackCacheConfig {

    /**
     * @return the directory where cached data is written to disk
     */
    @Nonnull
    Path getCacheDir();

    /**
     * When eviction is triggered the amount of disk space requested for eviction is calculated as
     * {@code (eviction.hysteresis + eviction.trigger.free.space - free space under cache-dir)}
     * @return the cache hysteresis in bytes
     */
    long getEvictionHysteresis();

    /**
     * @return the threshold at which eviction is triggered in terms of free space available on disk (in bytes)
     */
    long getEvictionTriggerFreeSpace();

    /**
     * @return how frequently expired cache entries are invalidated and removed from the cache
     */
    @Nonnull
    Duration getExpiryCheckInterval();

    /**
     * @return the maximum number of cache entries to retain (per repository)
     */
    @ManagedByControlPlane
    int getMaxCount();

    /**
     * @return how much space (in bytes) needs to be available on disk (specifically under the
     *         {@link #getCacheDir() cache dir}) for caching to be enabled
     */
    @ManagedByControlPlane
    long getMinimumFreeSpace();

    /**
     * @return the time to live in seconds. {@code -1} if caches don't expire.
     */
    @ManagedByControlPlane
    long getTimeToLive();

    /**
     * @return whether caching is enabled (for any protocol)
     */
    @ManagedByControlPlane
    boolean isEnabled();

    /**
     * @return whether caching is enabled for the HTTP(S) protocol.
     */
    @ManagedByControlPlane
    boolean isEnabledForHttp();

    /**
     * @return whether caching is enabled for the SSH protocol.
     */
    @ManagedByControlPlane
    boolean isEnabledForSsh();
}
