package top.r3944realms.lib39.api.callback;

import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.server.Services;

import java.util.concurrent.Executor;

/**
 * The interface Minecraft set up service callback.
 */
@FunctionalInterface
public interface MinecraftSetUpServiceCallback {
    /**
     * The constant EVENT.
     */
    Event<MinecraftSetUpServiceCallback> EVENT =
            EventFactory.createArrayBacked(
                    MinecraftSetUpServiceCallback.class,
                    (listeners) -> ((services, mainThreadExecutor) -> {
                        for (MinecraftSetUpServiceCallback listener : listeners) {
                            ActionResult result = listener.load(services, mainThreadExecutor);
                            if (result != ActionResult.PASS) {
                                return result;
                            }
                        }
                        return ActionResult.PASS;
                    })
            );

    /**
     * Load boolean.
     *
     * @param services           the services
     * @param mainThreadExecutor the main thread executor
     * @return 结果枚举 action result
     */
    ActionResult load(Services services, Executor mainThreadExecutor);
}
