package com.atlassian.bitbucket.test.rest.commit;

import com.atlassian.bitbucket.test.rest.HasBody;
import net.sf.json.JSONObject;

import javax.annotation.Nonnull;
import javax.ws.rs.core.Response;

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

public class RestAddCommitCommentRequest extends AbstractRestCommitCommentsRequest implements HasBody {

    private final JSONObject body;

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

        body = builder.body;
    }

    @Nonnull
    @Override
    public JSONObject getBody() {
        return body;
    }

    public static class Builder extends AbstractCommitCommentBuilder<Builder, RestAddCommitCommentRequest> {

        private final JSONObject body;

        public Builder(@Nonnull JSONObject body) {
            this.body = checkNotNull(body, "body");

            status(Response.Status.CREATED);
        }

        public Builder(@Nonnull RestAddCommitCommentRequest request) {
            super(request);

            body = checkNotNull(request.getBody(), "request.body");

            status(Response.Status.CREATED);
        }

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

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