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

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 UpdateRefParameters extends AbstractParameters {

    private final boolean dereferenceSymbolicRefs;
    private final Repository repository;
    private final ProposedRefUpdate update;

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

        dereferenceSymbolicRefs = builder.dereferenceSymbolicRefs;
        repository = builder.repository;
        update = builder.update;
    }

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

    @Nonnull
    public ProposedRefUpdate getUpdate() {
        return update;
    }

    public boolean isDereferenceSymbolicRefs() {
        return dereferenceSymbolicRefs;
    }

    public static class Builder extends AbstractBuilder<Builder, UpdateRefParameters> {

        private final Repository repository;
        private final ProposedRefUpdate update;

        private boolean dereferenceSymbolicRefs;

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

            dereferenceSymbolicRefs = true;
        }

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

        @Nonnull
        public Builder dereferenceSymbolicRefs(boolean value) {
            dereferenceSymbolicRefs = value;

            return self();
        }

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