package com.atlassian.bitbucket.mesh.git.push;

import com.atlassian.bitbucket.mesh.git.ref.RefUpdate;
import com.atlassian.bitbucket.mesh.rpc.v1.RpcPushResultFragment;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;

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

import static com.atlassian.bitbucket.mesh.rpc.util.ByteStringUtils.toStringsLazily;

public class PushResult {

    private final ImmutableList.Builder<String> failedRefs = ImmutableList.builder();
    private final ImmutableList.Builder<RefUpdate> refUpdates = ImmutableList.builder();

    public void add(@Nonnull RpcPushResultFragment fragment) {
        failedRefs.addAll(toStringsLazily(fragment.getFailedRefIdsList()));
        refUpdates.addAll(Lists.transform(fragment.getRefUpdatesList(), RefUpdate::of));
    }

    @Nonnull
    public List<String> getFailedRefs() {
        return failedRefs.build();
    }

    @Nonnull
    public List<RefUpdate> getRefUpdates() {
        return refUpdates.build();
    }
}
