package com.atlassian.bitbucket.web.conditions;

import com.atlassian.plugin.PluginParseException;
import com.atlassian.plugin.web.Condition;
import com.atlassian.bitbucket.server.ApplicationStatusService;

import java.util.Map;

/**
 * This Condition is true when the server has begun rejecting requests due to resource exhaustion.
 */
public class ResourceExhaustedCondition implements Condition {

    private final ApplicationStatusService applicationStatusService;

    public ResourceExhaustedCondition(ApplicationStatusService applicationStatusService) {
        this.applicationStatusService = applicationStatusService;
    }

    @Override
    public void init(Map<String, String> stringStringMap) throws PluginParseException {
    }

    @Override
    public boolean shouldDisplay(Map<String, Object> stringObjectMap) {
        return applicationStatusService.hasRecentlyRejectedRequests();
    }
}
