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

import com.atlassian.bitbucket.repository.Tag;
import com.atlassian.bitbucket.repository.TagCallback;
import com.atlassian.bitbucket.repository.TagContext;
import com.atlassian.bitbucket.repository.TagSummary;
import com.atlassian.bitbucket.scm.CommandSummary;

import javax.annotation.Nonnull;
import java.io.IOException;

/**
 * @since 4.6
 */
public class ForEachTagCallback extends AbstractForEachRefCallback<Tag> {

    private static final TagContext CONTEXT = new TagContext.Builder().build();

    private final TagCallback delegate;

    public ForEachTagCallback(TagCallback delegate, String filterText) {
        super(ForEachTagParser.INSTANCE, filterText);

        this.delegate = delegate;
    }

    @Override
    protected void onEnd(@Nonnull CommandSummary summary) throws IOException {
        delegate.onEnd(new TagSummary.Builder(summary).build());
    }

    @Override
    protected boolean onRef(@Nonnull Tag ref) throws IOException {
        return delegate.onTag(ref);
    }

    @Override
    protected void onStart() throws IOException {
        delegate.onStart(CONTEXT);
    }
}
