package com.atlassian.stash.internal.idx;

import com.atlassian.bitbucket.NoSuchResourceException;
import com.atlassian.bitbucket.repository.Repository;

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

public interface RepositorySnapshotService {

    /**
     * Creates a snapshot file that contains all the refs (branches and tags) for {@code repository}
     * @param repository the repository
     * @param timestamp the snapshot timestamp
     */
    Iterable<String> create(@Nonnull Repository repository, @Nonnull Long timestamp);

    /**
     * Deletes all snapshot files for a repository
     * @param repository the repository
     */
    void deleteByRepository(@Nonnull Repository repository);

    /**
     * Retrieves and reads from the snapshot file for {@code timestamp}.
     * @param repository the repository
     * @param timestamp the snapshot timestamp
     * @return an {@link Iterable} containing all commit hashes for the snapshot at {@code timestamp}
     * @throws NoSuchResourceException if no snapshot exists for the provided timestamp
     */
    @Nonnull
    Iterable<String> getByRepository(@Nonnull Repository repository, @Nullable Long timestamp);

    /**
     * Deletes all snapshot files for the provided repository, except for the ones in {@code timestampsToKeep}
     * @param repository the repository to process
     * @param timestampsToKeep the set of snapshots to keep
     * @since 1.1
     */
    void pruneByRepository(@Nonnull Repository repository, @Nonnull Set<Long> timestampsToKeep);
}
