package com.atlassian.bitbucket.mesh.repository;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Map;
import java.util.Set;

public interface RepositoryAttributeDao {

    /**
     * Deletes the attributes for the specified repository
     *
     * @param id the repository
     */
    void delete(@Nonnull String id);

    /**
     * Get the content hash for the specified repository.
     *
     * @param id the repository
     * @return a content hash, or {@code null} if no content hash has been set for the given repository
     */
    @Nullable
    String getContentHash(@Nonnull String id);

    /**
     * Get the metadata hash for the specified repository.
     *
     * @param id the repository
     * @return a metadata hash, or {@code null} if no metadata hash has been set for the given repository
     */
    @Nullable
    String getMetadataHash(@Nonnull String id);

    /**
     * Retrieves the version for the specified repository.
     *
     * @param id the repository
     * @return the repository version
     */
    long getVersion(@Nonnull String id);

    /**
     * Retrieves the versions for all managed repositories in the provided set of partitions.
     *
     * @param partitions the partitions to filter by; empty means "any partition"
     * @return the (order preserving) map of matching IDs to their version
     * @since 1.4
     */
    @Nonnull
    Map<String, Long> getVersionsByPartitions(@Nonnull Set<String> partitions);

    /**
     * Increments the version for the specified repository.
     *
     * @param id the repository
     * @return the incremented version
     */
    long incrementAndGetVersion(@Nonnull String id);

    /**
     * Retrieves the read-only status for the specified repository.
     *
     * @param id the repository to check
     * @return {@code true} if the repository is read-only, otherwise {@code false}
     */
    boolean isReadOnly(@Nonnull String id);

    /**
     * Replaces the set of read-only repositories with the given one. Specifically, a set of repository IDs are taken
     * and any repositories not in that set are assumed to be read/write while repositories in the set are read-only.
     *
     * @param repositoryIds the repository IDs that are read-only
     */
    void replaceReadOnly(@Nonnull Collection<String> repositoryIds);

    /**
     * Stores the content hash for the specified repository.
     *
     * @param id          the repository
     * @param contentHash a content hash, or {@code null} to indicate the absence of a content hash
     */
    void setContentHash(@Nonnull String id, @Nullable String contentHash);

    /**
     * Stores the metadata hash for the specified repository.
     *
     * @param id           the repository
     * @param metadataHash a metadata hash, or {@code null} to indicate the absence of a metadata hash
     */
    void setMetadataHash(@Nonnull String id, @Nullable String metadataHash);

    /**
     * Enable/disable read-only for the specified repository.
     *
     * @param id       the repository to enable/disable read-only on
     * @param readOnly {@code true} to enable read-only mode; {@code false} to disable
     */
    void setReadOnly(@Nonnull String id, boolean readOnly);

    /**
     * Updates the version for the specified repository.
     *
     * @param id      the repository
     * @param version the version
     */
    void setVersion(@Nonnull String id, long version);
}
