package cn.stylefeng.workflow.instance.modular.message;

import cn.hutool.extra.spring.SpringUtil;
import cn.stylefeng.workflow.api.entity.task.RuTask;
import cn.stylefeng.workflow.api.pojo.InstanceContext;
import cn.stylefeng.workflow.api.pojo.config.node.notice.NodeNotice;

import java.util.List;
import java.util.Map;

public class TaskMessageSendFactory {

    public static void taskMessageSend(List<RuTask> ruTasks, NodeNotice nodeNotice, InstanceContext instanceContext) {

        Map<String, TaskMessageApi> taskMessageApiMap = SpringUtil.getBeansOfType(TaskMessageApi.class);

        for (RuTask ruTask : ruTasks) {

            for (TaskMessageApi taskMessageApi : taskMessageApiMap.values()) {
                if (taskMessageApi.validateSendFlag(nodeNotice)) {
                    taskMessageApi.sendMessage(ruTask.getApprover(), ruTask, nodeNotice, instanceContext);
                }
            }
        }

    }

}
