package com.atlassian.stash.internal.scm.git.command.foreachref;

import com.atlassian.bitbucket.repository.Ref;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
 * A parser for constructing a {@code Ref} from {@code git for-each-ref} output.
 *
 * @since 4.6
 */
public interface ForEachRefParser<T extends Ref> {

    /**
     * @return the {@code git for-each-ref} format this parser expects
     */
    @Nonnull
    String getFormat();

    /**
     * Parses the provided line of {@code git for-each-ref} output, which is expected to be in the parser's
     * specified {@link #getFormat format}, and returns the resulting {@code Ref}. If the output is not in
     * the required format, {@code null} is returned instead.
     *
     * @param line the line to parse
     * @return the parsed {@link Ref}
     */
    @Nullable
    T parse(@Nonnull String line);
}
