package com.atlassian.bitbucket.internal.ssh.server;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException;

import static com.google.common.base.Preconditions.checkNotNull;

/**
 * @since 3.7
 */
public class SshServerStatus {

    private final IOException failureCause;
    private final SshServerState state;

    private SshServerStatus(SshServerState state, IOException failureCause) {
        this.failureCause = failureCause;
        this.state = checkNotNull(state, "state");
    }

    @Nonnull
    public static SshServerStatus forException(@Nonnull IOException exception) {
        return new SshServerStatus(SshServerState.FAILED_TO_START, checkNotNull(exception, "exception"));
    }

    @Nonnull
    public static SshServerStatus forState(@Nonnull SshServerState state) {
        return new SshServerStatus(state, null);
    }

    @Nullable
    public IOException getFailureCause() {
        return failureCause;
    }

    @Nonnull
    public SshServerState getState() {
        return state;
    }
}
