package com.atlassian.stash.rest.pull;

import com.atlassian.bitbucket.hook.repository.RepositoryMergeRequestCheckContext;
import com.atlassian.bitbucket.hook.repository.RepositoryMergeRequestCheck;
import com.atlassian.bitbucket.scm.pull.MergeRequest;

import javax.annotation.Nonnull;
import java.util.Locale;

import static com.atlassian.stash.rest.pull.VetoingMergeCheck.VETO_DETAIL;
import static com.atlassian.stash.rest.pull.VetoingMergeCheck.VETO_SUMMARY;

public class VetoingRepositoryMergeRequestCheck implements RepositoryMergeRequestCheck {

    @Override
    public void check(@Nonnull RepositoryMergeRequestCheckContext context) {
        MergeRequest request = context.getMergeRequest();
        if (request.getPullRequest().getTitle().toLowerCase(Locale.US).equals("veto-merge-check")) {
            request.veto(VETO_SUMMARY, VETO_DETAIL);
        }
    }
}
