package ninja.academy.vertx.market.seller.alternative.endpoint;

import io.vertx.core.eventbus.EventBus;
import io.vertx.core.eventbus.Message;
import ninja.academy.vertx.market.seller.alternative.storage.GeneratedShapesStorage;

import javax.inject.Inject;

public class ShapeIdConfirmationEndpoint {

    private static final String CHANNEL_SHAPE_ID_CHECK = "espeo.vertx.workshop.shape_id_confirmation";

    @Inject
    private EventBus eventBus;
    @Inject
    private GeneratedShapesStorage shapesStorage;

    public void init(){
        eventBus.consumer(CHANNEL_SHAPE_ID_CHECK, this::checkShapeIdValidity);
    }

    private void checkShapeIdValidity(Message<Object> message) {
        shapesStorage.shapePresent(message.body().toString(), event
                -> message.reply(Boolean.toString(event.booleanValue())));
    }



}
