package com.atlassian.bitbucket.internal.mirroring.mirror;

import com.atlassian.event.api.EventPublisher;
import com.atlassian.johnson.event.AddEvent;
import com.atlassian.johnson.event.Event;
import com.atlassian.johnson.event.EventLevel;
import com.atlassian.johnson.event.EventType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Nonnull;

@Component
public class DefaultJohnsonHelper implements JohnsonHelper {

    private final EventPublisher eventPublisher;

    @Autowired
    public DefaultJohnsonHelper(EventPublisher eventPublisher) {
        this.eventPublisher = eventPublisher;
    }

    @Override
    public void addJohnsonEvent(@Nonnull String eventType, @Nonnull String message, @Nonnull String level) {
        Event johnsonEvent = new Event(EventType.get(eventType), message, EventLevel.get(level));
        eventPublisher.publish(new AddEvent(this, johnsonEvent));
    }
}
