package com.atlassian.bitbucket.internal.crowd.sso;

import com.atlassian.crowd.embedded.api.Directory;
import com.atlassian.crowd.integration.http.CrowdHttpAuthenticator;
import com.atlassian.crowd.service.client.ClientProperties;
import org.apache.commons.lang3.StringUtils;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
 * Represents a Crowd SSO configuration
 *
 * @since 2.3
 */
class SsoConfiguration {
    private final CrowdHttpAuthenticator authenticator;
    private final String cookieDomain;
    private final Directory ssoDirectory;
    private final ClientProperties clientProperties;

    SsoConfiguration(CrowdHttpAuthenticator authenticator, String cookieDomain, Directory ssoDirectory,
                     ClientProperties clientProperties) {
        this.authenticator = authenticator;
        this.cookieDomain = StringUtils.defaultString(cookieDomain);
        this.ssoDirectory = ssoDirectory;
        this.clientProperties = clientProperties;
    }

    @Nullable
    CrowdHttpAuthenticator getAuthenticator() {
        return authenticator;
    }

    @Nonnull
    String getCookieDomain() {
        return cookieDomain;
    }

    @Nullable
    Directory getSsoDirectory() {
        return ssoDirectory;
    }

    boolean isValid() {
        return authenticator != null && ssoDirectory != null;
    }

    @Nullable
    ClientProperties getClientProperties() {
        return clientProperties;
    }
}
