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

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

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

import static com.google.common.base.Strings.emptyToNull;
import static java.util.Objects.requireNonNull;

public class CreateTagParameters extends AbstractCreateRefParameters {

    private final String message;
    private final GitTagType type;

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

        message = builder.message;
        type = builder.type;
    }

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

    @Nonnull
    public GitTagType getType() {
        return type;
    }

    public static class Builder extends AbstractCreateBuilder<Builder, CreateTagParameters> {

        private String message;
        private GitTagType type;

        public Builder(@Nonnull Repository repository, @Nonnull String name) {
            super(repository, name);

            type = GitTagType.ANNOTATED;
        }

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

        @Nonnull
        public Builder message(@Nullable String value) {
            message = emptyToNull(value);

            return self();
        }

        @Nonnull
        public Builder type(@Nonnull GitTagType value) {
            type = requireNonNull(value, "type");

            return self();
        }

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