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

import com.atlassian.bitbucket.mesh.git.AbstractParameters;
import com.atlassian.bitbucket.mesh.repository.Repository;

import javax.annotation.Nonnull;

import static java.util.Objects.requireNonNull;

public class StreamRefsParameters extends AbstractParameters {

    private final boolean failOnInvalidRefs;
    private final boolean includeDarkRefs;
    private final boolean includePublicRefs;
    private final boolean includeStashRefs;
    private final Repository repository;

    private StreamRefsParameters(Builder builder) {
        super(builder);

        failOnInvalidRefs = builder.failOnInvalidRefs;
        includeDarkRefs = builder.includeDarkRefs;
        includePublicRefs = builder.includePublicRefs;
        includeStashRefs = builder.includeStashRefs;
        repository = builder.repository;
    }

    @Nonnull
    public Repository getRepository() {
        return repository;
    }

    public boolean isFailOnInvalidRefs() {
        return failOnInvalidRefs;
    }

    public boolean isIncludeDarkRefs() {
        return includeDarkRefs;
    }

    public boolean isIncludePublicRefs() {
        return includePublicRefs;
    }

    public boolean isIncludeStashRefs() {
        return includeStashRefs;
    }

    public static class Builder extends AbstractParameters.AbstractBuilder<Builder, StreamRefsParameters> {

        private final Repository repository;

        private boolean failOnInvalidRefs;
        private boolean includeDarkRefs;
        private boolean includePublicRefs;
        private boolean includeStashRefs;

        public Builder(@Nonnull Repository repository) {
            this.repository = requireNonNull(repository, "repository");

            includePublicRefs = true;
            failOnInvalidRefs = true;
        }

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

        @Nonnull
        public Builder darkRefs(boolean value) {
            includeDarkRefs = value;
            return self();
        }

        @Nonnull
        public Builder failOnInvalidRefs(boolean value) {
            failOnInvalidRefs = value;
            return self();
        }

        @Nonnull
        public Builder publicRefs(boolean value) {
            includePublicRefs = value;
            return self();
        }

        @Nonnull
        public Builder stashRefs(boolean value) {
            includeStashRefs = value;
            return self();
        }

        @Nonnull
        @Override
        protected Builder self() {
            return this;
        }
    }
}
