package com.atlassian.bitbucket.internal.mirroring.mirror.client;

import com.atlassian.bitbucket.i18n.KeyedMessage;
import com.atlassian.bitbucket.mirroring.mirror.UpstreamServerType;

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

/**
 * Validate that a server may be used as an upstream.
 */
public interface UpstreamValidator {
    /**
     * Validate that a server located by the passed URL may be used as an upstream. It is possible for the
     * registration to fail on the passed URL even when this method returns success.
     *
     * @param type the type of upstream to check.
     * @param url the URL to check
     * @return {@link Optional#empty()} if the URL is valid or a {@link KeyedMessage} for any error.
     */
    @Nonnull
    Optional<KeyedMessage> validate(@Nonnull UpstreamServerType type, @Nonnull String url);
}
