package p.studio.lsp.events;

import p.packer.events.PackerEvent;
import p.packer.events.PackerEventSink;

import java.util.Objects;

public final class StudioPackerEventAdapter implements PackerEventSink {
    private final StudioEventBus eventBus;

    public StudioPackerEventAdapter(StudioEventBus eventBus) {
        this.eventBus = Objects.requireNonNull(eventBus, "eventBus");
    }

    @Override
    public void publish(PackerEvent event) {
        final PackerEvent packerEvent = Objects.requireNonNull(event, "event");
        eventBus.publish(new StudioPackerOperationEvent(
                packerEvent.operationId(),
                packerEvent.kind(),
                packerEvent.summary(),
                packerEvent.progress() == null ? null : packerEvent.progress().value(),
                packerEvent.progress() == null || packerEvent.progress().indeterminate()));
    }
}
