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

import com.atlassian.bitbucket.mesh.git.builder.GitProcessBuilderSupport;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.nio.file.Path;

/**
 * A builder for {@code git index-pack} commands.
 */
public interface GitIndexPackBuilder extends GitProcessBuilderSupport<GitIndexPackBuilder> {

    /**
     * Controls the {@code --fix-thin} flag. When set to {@code true}, a "thin" pack produced by
     * {@code git pack-objects --thin} is fixed by adding the excluded objects the deltified objects are based
     * on to the pack.
     *
     * @param value whether to enable the {@code --fix-thin} flag
     * @return the builder
     */
    @Nonnull
    GitIndexPackBuilder fixThin(boolean value);

    /**
     * The location where the index file should be created. If set to {@code null}, the index file location is
     * constructed from the name of packed archive file by replacing .pack with .idx.
     *
     * @param value the pack file location
     * @return the builder
     */
    @Nonnull
    GitIndexPackBuilder indexFile(@Nullable Path value);

    /**
     * Controls the {@code --keep} flag. When set to {@code true}, a {@code .keep} file is created in the target
     * directory to protect the newly created pack file from being deleted by garbage collection.
     *
     * @param value whether to enable the {@code --keep} flag
     * @return the builder
     */
    @Nonnull
    GitIndexPackBuilder keep(boolean value);

    /**
     * The location of the pack file to read. If set to {@code null} and {@link #stdin(boolean) --stdin} is enabled,
     * the pack is written to the {@code objects/pack/} directory of the target repository with a default name
     * determined from the pack content.
     *
     * @param value the pack file location
     * @return the builder
     */
    @Nonnull
    GitIndexPackBuilder packFile(@Nullable Path value);

    /**
     * Controls the {@code --stdin} flag. When set to {@code true}, the pack is read from stdin and a copy is
     * written to {@link #packFile pack-file}. If no file is specified, the pack is written to the {@code objects/pack/}
     * directory of the target repository with a default name determined from the pack content.
     *
     * @param value whether to enable the {@code --stdin} flag
     * @return the builder
     */
    @Nonnull
    GitIndexPackBuilder stdin(boolean value);

    /**
     * Controls the {@code --strict} flag. When set to {@code true}, {@code index-pack} will fails if the pack
     * contains broken objects or links.
     *
     * @param value whether to enable the {@code --strict} flag
     * @return the builder
     */
    @Nonnull
    GitIndexPackBuilder strict(boolean value);
}
