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

import com.atlassian.bitbucket.mesh.git.commit.Commit;

import javax.annotation.Nonnull;
import java.util.Optional;

import static java.util.Objects.requireNonNull;
import static java.util.Optional.ofNullable;

/**
 * Enumerates {@link Commit#getMessage() message} modes supported by {@link CommitPumpSettings}
 */
public enum CommitMessageMode {

    /**
     * Retrieves the body of the commit message <i>without the {@link #SUBJECT subject}</i>. This maps to
     * {@code %b} in a {@code git rev-list --format}.
     */
    BODY("%b"),
    /**
     * Omits the commit message entirely, leaving {@link Commit#getMessage()} {@code null}.
     */
    NONE,
    /**
     * Retrieves the raw body of the commit message, which includes both the {@link #SUBJECT subject} and
     * the {@link #BODY body}. This maps to {@code %B} in a {@code git rev-list --format}.
     * <p>
     * This is the <i>default mode</i>.
     */
    RAW_BODY("%B"),
    /**
     * Retrieves the <i>Git-determined</i> subject for the commit message. The subject includes text up
     * to the first occurrence of two newlines.
     */
    SUBJECT("%s");

    private final String placeholder;

    CommitMessageMode() {
        placeholder = null;
    }

    CommitMessageMode(@Nonnull String placeholder) {
        this.placeholder = requireNonNull(placeholder, "placeholder");
    }

    /**
     * @return the {@code git rev-list --format} placeholder for this message mode, which is {@code empty()}
     *         for {@link #NONE}
     */
    @Nonnull
    public Optional<String> getPlaceholder() {
        return ofNullable(placeholder);
    }
}