package com.atlassian.stash.internal.scm;

import com.atlassian.bitbucket.scm.AvailableScm;
import com.atlassian.bitbucket.util.BuilderSupport;

import javax.annotation.Nonnull;

import static com.google.common.base.Preconditions.checkState;

/**
 * @since 3.3
 */
public class SimpleAvailableScm implements AvailableScm {

    private final String id;
    private final String name;

    private SimpleAvailableScm(Builder builder) {
        id = builder.id;
        name = builder.name;
    }

    @Nonnull
    @Override
    public String getId() {
        return id;
    }

    @Nonnull
    @Override
    public String getName() {
        return name;
    }

    public static class Builder extends BuilderSupport {

        private final String id;

        private String name;

        public Builder(@Nonnull String id) {
            this.id = checkNotBlank(id, "id");
        }

        @Nonnull
        public SimpleAvailableScm build() {
            checkState(name != null, "An SCM name is required");

            return new SimpleAvailableScm(this);
        }

        @Nonnull
        public Builder name(@Nonnull String value) {
            name = checkNotBlank(value, "name");

            return this;
        }
    }
}
