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

import com.atlassian.bitbucket.test.rest.AbstractEnrichableRestRequest;
import org.apache.commons.lang3.StringUtils;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Map;

public class AbstractRestCommitCommentsRequest extends AbstractEnrichableRestRequest {

    private final String since;

    protected AbstractRestCommitCommentsRequest(AbstractCommitCommentBuilder<?, ?> builder) {
        super(builder);

        since = builder.since;
    }

    @Nullable
    public String getSince() {
        return since;
    }

    @Nonnull
    @Override
    public Map<String, Object> toQueryParams() {
        Map<String, Object> params = super.toQueryParams();
        if (since != null) {
            params.put("since", since);
        }

        return params;
    }

    protected abstract static class AbstractCommitCommentBuilder<B extends AbstractCommitCommentBuilder<B, R>, R extends AbstractRestCommitCommentsRequest>
            extends AbstractEnrichableBuilder<B, R> {

        private String since;

        protected AbstractCommitCommentBuilder() {
        }

        protected AbstractCommitCommentBuilder(@Nonnull R request) {
            super(request);
        }

        @Nonnull
        public B since(@Nullable String value) {
            since = StringUtils.trimToNull(value);

            return self();
        }
    }
}
