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

import com.atlassian.bitbucket.mesh.git.AbstractParameters;
import com.atlassian.bitbucket.mesh.util.Person;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import static java.util.Objects.requireNonNull;

public class PublishWorkTreeParameters extends AbstractParameters {

    private final Person author;
    private final String branch;
    private final String expectedHash;

    private PublishWorkTreeParameters(Builder builder) {
        super(builder);
        branch = requireNonNull(builder.branch, "branch");
        author = builder.author;
        expectedHash = builder.expectedHash;
    }

    @Nullable
    public Person getAuthor() {
        return author;
    }

    @Nonnull
    public String getBranch() {
        return branch;
    }

    @Nullable
    public String getExpectedHash() {
        return expectedHash;
    }

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

        private Person author;
        private String branch;
        private String expectedHash;

        @Nonnull
        public Builder author(@Nullable Person value) {
            author = value;

            return this;
        }

        @Nonnull
        public Builder branch(@Nonnull String value) {
            branch = requireNonBlank(value, "branch");

            return this;
        }

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

        public Builder expectedHash(@Nullable String value) {
            expectedHash = value;

            return this;
        }

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