package com.atlassian.bitbucket.mesh.repository;

import com.atlassian.bitbucket.mesh.util.BuilderSupport;
import com.google.common.collect.ImmutableSet;
import org.apache.commons.lang3.StringUtils;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Set;

/**
 * @since 1.4
 */
public class GetVersionsParameters {

    private final Set<String> partitions;

    private GetVersionsParameters(Builder builder) {
        partitions = builder.partitions.build();
    }

    /**
     * @return the partitions to filter by; when empty, no partition filtering is done
     */
    @Nonnull
    public Set<String> getPartitions() {
        return partitions;
    }

    public static class Builder extends BuilderSupport {

        private final ImmutableSet.Builder<String> partitions;

        public Builder() {
            partitions = ImmutableSet.builder();
        }

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

        @Nonnull
        public Builder partitions(@Nullable String value, @Nullable String... moreValues) {
            addIf(StringUtils::isNotBlank, partitions, value, moreValues);
            return this;
        }

        @Nonnull
        public Builder partitions(@Nullable Iterable<String> values) {
            addIf(StringUtils::isNotBlank, partitions, values);
            return this;
        }
    }
}
