package com.atlassian.bitbucket.mesh.git.builder.lstree;

import com.atlassian.bitbucket.mesh.git.content.Directory;

import javax.annotation.Nonnull;

/**
 * Creates a {@link Directory} from a path and content ID.
 * <p>
 * This is a separate interface from {@code DirectoryLsTreeStdioHandler} to allow more sophisticated control
 * over directories, with the primary use case being support for pluggable "collapsing", where directories
 * that contain only a single nested directory are combined (potentially several layers deep). While this
 * could be accomplished using subclasses or other approaches, the advantage of this one is it's testability,
 * since it allows the creators to be standalone components.
 */
public interface DirectoryCreator extends AutoCloseable {

    /**
     * Closes the creator, ensuring any resources (such as additional processes) it is using are released.
     */
    @Override
    void close();

    /**
     * Creates a {@link Directory}, given its path and content ID.
     *
     * @param path      the directory's path
     * @param contentId the directory's content ID (e.g. a SHA identifying its tree)
     * @return the created directory
     */
    @Nonnull
    Directory create(@Nonnull String path, @Nonnull String contentId);
}
