package com.atlassian.bitbucket.project;

import org.apache.commons.lang3.StringUtils;

import javax.annotation.Nonnull;

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

/**
 * @see ProjectService#update(ProjectUpdateRequest)
 */
public class ProjectUpdateRequest extends AbstractProjectRequest {

    private final int id;

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

        id = builder.id;
    }

    /**
     * @return the id of the projects to be updated
     */
    public int getId() {
        return id;
    }

    public static class Builder extends AbstractBuilder<Builder> {

        private final int id;

        public Builder(@Nonnull Project project) {
            super(project);

            id = project.getId();
        }

        public Builder(int id) {
            this.id = id;
        }

        @Nonnull
        public ProjectUpdateRequest build() {
            checkState(StringUtils.isNotBlank(key), "The key with which to update the project is required");
            checkState(StringUtils.isNotBlank(name), "The name with which to update the project is required");

            return new ProjectUpdateRequest(this);
        }

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