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

import com.atlassian.bitbucket.mesh.rpc.v1.RpcMergeConflict;
import com.atlassian.bitbucket.mesh.util.BuilderSupport;
import com.google.common.collect.ImmutableList;

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

import static java.util.Objects.requireNonNull;

public class GitMergeConflict {

    private final String message;
    private final List<String> moreMessages;

    private GitMergeConflict(Builder builder) {
        message = builder.message;
        moreMessages = builder.moreMessages.build();
    }

    @Nonnull
    public String getMessage() {
        return message;
    }

    @Nonnull
    public List<String> getMoreMessages() {
        return moreMessages;
    }

    @Nonnull
    public RpcMergeConflict toMergeConflict() {
        return RpcMergeConflict.newBuilder()
                .addAllMoreMessages(moreMessages)
                .setMessage(message)
                .build();
    }

    public static class Builder extends BuilderSupport {

        private final String message;
        private final ImmutableList.Builder<String> moreMessages;

        public Builder(@Nonnull String message) {
            this.message = requireNonNull(message, "message");

            moreMessages = ImmutableList.builder();
        }

        @Nonnull
        public GitMergeConflict build() {
            return new GitMergeConflict(this);
        }

        @Nonnull
        public Builder message(@Nonnull String value) {
            moreMessages.add(requireNonNull(value, "message"));

            return this;
        }
    }
}
