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

import cokr.xit.ens.core.monitor.slack.struct.SlackSenderStrategy;
import cokr.xit.ens.core.monitor.slack.support.ChannelGetter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@RequiredArgsConstructor
@Component
public class SlackMessage {

    @Value("${slack.token}")
    private String TOKEN;
    @Value("${slack.api.users}")
    private String API_USERS;
    @Value("${slack.recev.emails}")
    private List<String> emails;

    public void send(SlackSenderStrategy sender) {
        for (String email : emails) {
            try {
                sender.execute(TOKEN, ChannelGetter.builder()
                        .TOKEN(TOKEN)
                        .API_URL(API_USERS)
                        .email(email)
                        .build()
                        .execute());
            } catch (Exception e) {
                log.info("Slack 전송 실패", e);
            }
        }
    }

    ;
}
