package com.docus.server.message.service;

import cn.hutool.http.HttpUtil;
import com.docus.core.util.Func;
import com.docus.server.message.config.MessageForwardConfig;
import com.docus.server.message.dto.Message;
import com.docus.server.message.dto.MessageResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
@Slf4j
public class MessageCarrier {
    public List<MessageResponse> send(Message message, MessageForwardConfig.MessageForward messageForward) {
        List<MessageResponse> responseLis = new ArrayList<>();
        for (String url : messageForward.getUrls()) {
            String resp = HttpUtil.post(url, Func.toJson(message));
            responseLis.add(Func.readJson(resp, MessageResponse.class));
        }
        return responseLis;
    }
}
