package com.atlassian.bitbucket.rest.pull;

import com.atlassian.bitbucket.pull.PullRequestMergeVeto;
import com.atlassian.bitbucket.rest.annotation.JsonSurrogate;
import com.atlassian.bitbucket.rest.RestMapEntity;
import org.apache.commons.lang3.StringUtils;
import org.codehaus.jackson.map.annotate.JsonSerialize;

import java.util.function.Function;

@JsonSerialize
@JsonSurrogate(PullRequestMergeVeto.class)
public class RestPullRequestMergeVeto extends RestMapEntity {

    public static final Function<PullRequestMergeVeto, RestPullRequestMergeVeto> REST_TRANSFORM =
            RestPullRequestMergeVeto::new;

    public RestPullRequestMergeVeto(PullRequestMergeVeto preCondition) {
        this(preCondition.getSummaryMessage(), preCondition.getDetailedMessage());
    }

    private RestPullRequestMergeVeto(String summaryMessage, String detailedMessage) {
        put("summaryMessage", summaryMessage);
        if (StringUtils.isNotBlank(detailedMessage)) {
            put("detailedMessage", detailedMessage);
        }
    }

    public static final RestPullRequestMergeVeto RESPONSE_EXAMPLE = new RestPullRequestMergeVeto(
        "You may not merge after 6pm on a Friday.",
        "It is likely that your Blood Alcohol Content (BAC) exceeds the threshold for making sensible decisions " +
        "regarding pull requests. Please try again on Monday."
    );

}
