package dev.photosync.core.provider.google;

import org.slf4j.LoggerFactory;

/**
 * How the player is put in front of Google's consent page.
 *
 * <p>Google Photos has no API key to paste: the only way to get a token is to
 * send the player to Google in a browser and catch what comes back. Core cannot
 * open a browser -- that is a Minecraft capability -- so the client module hands
 * one of these in, and this package stays free of the game.
 */
@FunctionalInterface
public interface SignInPrompt {

    /**
     * Shows {@code url} to the player, ideally by opening their browser.
     *
     * <p>Called from a worker thread, once per sign-in. It does not have to
     * succeed: the URL is logged as well, and the sign-in waits for the
     * redirect either way, so a player whose browser will not open can still
     * paste the link themselves.
     */
    void show(String url);

    /** The fallback when nobody supplied one: the log is the only way in. */
    static SignInPrompt logging() {
        return url -> LoggerFactory.getLogger(SignInPrompt.class)
                .info("Open this page to finish signing in to Google Photos: {}", url);
    }
}
