package cokr.xit.ens.core.monitor.slack.event;

import cokr.xit.ens.core.monitor.slack.support.MessageSender;
import cokr.xit.ens.core.monitor.slack.SlackMessage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RequiredArgsConstructor
public class MonitorEventListener {
    @Value("${slack.api.chat}")
    private String API_CHAT;
    private final SlackMessage slackMessage;

    @Order(1)
    @EventListener
//    @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
    public void send(MonitorEvent event) {
        slackMessage.send(MessageSender.builder()
                .API_URL(this.API_CHAT)
                .message(event.getMessage().create())
                .build());
    }

}
