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

import cokr.xit.ens.core.monitor.slack.struct.SlackSenderTemplate;
import lombok.experimental.SuperBuilder;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.entity.ContentType;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@SuperBuilder
public class MessageSender extends SlackSenderTemplate {

    private String message;


    @Override
    public void execute(String token, String channel) {

        Map<String, String> params = new HashMap<>();
        params.put("channel", channel);
        params.put("text", message);
        String body = gson.toJson(params);


        HttpEntity<String> requestEntity = new HttpEntity<>(body, this.createHeaders(ContentType.APPLICATION_JSON, token));
        RestTemplate restTemplate = new RestTemplate();
        ResponseEntity<String> responseEntity = restTemplate.exchange(API_URL, HttpMethod.POST, requestEntity, String.class);
        log.info("====================================================================");
        log.info("==== Slack Send-Message Response... ====");
        log.info(String.format("[ HttpStatusCode %d ]", responseEntity.getStatusCode().value()));
        log.info(responseEntity.getBody());
        log.info("====================================================================");
    }



}
