package com.atlassian.bitbucket.internal.key.ssh.condition;

import com.atlassian.bitbucket.ssh.SshConfiguration;
import com.atlassian.bitbucket.ssh.SshConfigurationService;
import com.atlassian.plugin.PluginParseException;
import com.atlassian.plugin.web.Condition;

import java.util.Map;

/**
 * Conditionally display web fragments based whether SSH Access Keys support has been
 * {@link SshConfiguration#isAccessKeysEnabled() enabled}
 */
public class SshAccessKeysEnabledCondition implements Condition {

    private final SshConfigurationService configurationService;

    public SshAccessKeysEnabledCondition(SshConfigurationService configurationService) {
        this.configurationService = configurationService;
    }

    @Override
    public void init(Map<String, String> params) throws PluginParseException {
        // no op
    }

    @Override
    public boolean shouldDisplay(Map<String, Object> context) {
        return configurationService.getConfiguration().isAccessKeysEnabled();
    }
}
