package de.gecheckt.pdf.umbenenner.adapter.in.gui;

import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;

/**
 * Process-local holder for the next GUI startup context.
 * <p>
 * JavaFX creates the application class reflectively, so Bootstrap installs the context here
 * immediately before the JavaFX launch call.
 */
final class GuiStartupContextHolder {

    private static final AtomicReference<GuiStartupContext> CONTEXT = new AtomicReference<>();

    private GuiStartupContextHolder() {
        // Utility class.
    }

    static void install(GuiStartupContext context) {
        CONTEXT.set(context);
    }

    static GuiStartupContext currentOrBlank() {
        return Optional.ofNullable(CONTEXT.get()).orElseGet(() -> GuiStartupContext.blank(Optional.empty()));
    }

    static void clear() {
        CONTEXT.set(null);
    }
}
