package cn.axzo.workflow.core.engine.event;

import cn.axzo.workflow.common.model.request.bpmn.BpmnNoticeConf;
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskDelegateAssigner;
import cn.axzo.workflow.core.common.exception.WorkflowEngineException;

import java.util.List;

import static cn.axzo.workflow.core.common.code.OtherRespCode.MES_PUSH_OBJECT_BUILD_ERROR;
import static cn.axzo.workflow.core.engine.event.MessagePushEventType.CARBON_COPY;
import static cn.axzo.workflow.core.engine.event.MessagePushEventType.CARBON_COPY_COMPLETE;
import static cn.axzo.workflow.core.engine.event.MessagePushEventType.NOTICE;
import static cn.axzo.workflow.core.engine.event.MessagePushEventType.PENDING_COMPLETE;
import static cn.axzo.workflow.core.engine.event.MessagePushEventType.PENDING_PUSH;
import static cn.axzo.workflow.core.engine.event.MessagePushEventType.SMS;

/**
 * 推送事件对象构造器
 *
 * @author wangli
 * @since 2023/11/22 14:16
 */
public class MessagePushEventBuilder {

    public static MessagePushEventImpl createEvent(MessagePushEventType type, List<BpmnTaskDelegateAssigner> assigners,
                                                   BpmnNoticeConf noticeConf, String processInstanceId,
                                                   String tenantId, String taskId) {
        switch (type) {
            case NOTICE:
                return createNoticeEvent(assigners, noticeConf, processInstanceId, tenantId, taskId);
            case PENDING_PUSH:
                return createPendingPushEvent(assigners, noticeConf, processInstanceId, tenantId, taskId);
            case PENDING_COMPLETE:
                return createPendingCompleteEvent(assigners, noticeConf, processInstanceId, tenantId, taskId);
            case CARBON_COPY:
                return createCarbonCopyEvent(assigners, noticeConf, processInstanceId, tenantId);
            case CARBON_COPY_COMPLETE:
                return createCarbonCopyCompleteEvent(assigners, noticeConf, processInstanceId, tenantId);
            case SMS:
                return createSmsEvent(assigners, noticeConf, processInstanceId, tenantId, taskId);
            default:
                throw new WorkflowEngineException(MES_PUSH_OBJECT_BUILD_ERROR);
        }
    }

    public static MessagePushEventImpl createNoticeEvent(List<BpmnTaskDelegateAssigner> assigners,
                                                         BpmnNoticeConf noticeConf
            , String processInstanceId, String tenantId, String taskId) {
        MessagePushEventImpl newEvent = new MessagePushEventImpl(NOTICE, assigners, noticeConf, processInstanceId,
                tenantId, taskId);
        return newEvent;
    }

    public static MessagePushEventImpl createPendingPushEvent(List<BpmnTaskDelegateAssigner> assigners,
                                                              BpmnNoticeConf noticeConf, String processInstanceId,
                                                              String tenantId, String taskId) {
        MessagePushEventImpl newEvent = new MessagePushEventImpl(PENDING_PUSH, assigners, noticeConf, processInstanceId,
                tenantId, taskId);
        return newEvent;
    }

    public static MessagePushEventImpl createPendingCompleteEvent(List<BpmnTaskDelegateAssigner> assigners,
                                                                  BpmnNoticeConf noticeConf, String processInstanceId,
                                                                  String tenantId, String taskId) {
        MessagePushEventImpl newEvent = new MessagePushEventImpl(PENDING_COMPLETE, assigners, noticeConf,
                processInstanceId,
                tenantId, taskId);
        return newEvent;
    }

    public static MessagePushEventImpl createCarbonCopyEvent(List<BpmnTaskDelegateAssigner> assigners,
                                                             BpmnNoticeConf noticeConf, String processInstanceId,
                                                             String tenantId) {
        MessagePushEventImpl newEvent = new MessagePushEventImpl(CARBON_COPY, assigners, noticeConf,
                processInstanceId, tenantId, null);
        return newEvent;
    }

    public static MessagePushEventImpl createCarbonCopyCompleteEvent(List<BpmnTaskDelegateAssigner> assigners,
                                                                     BpmnNoticeConf noticeConf, String processInstanceId,
                                                                     String tenantId) {
        MessagePushEventImpl newEvent = new MessagePushEventImpl(CARBON_COPY_COMPLETE, assigners, noticeConf,
                processInstanceId, tenantId, null);
        return newEvent;
    }

    public static MessagePushEventImpl createSmsEvent(List<BpmnTaskDelegateAssigner> assigners,
                                                      BpmnNoticeConf noticeConf,
                                                      String processInstanceId, String tenantId, String taskId) {
        MessagePushEventImpl newEvent = new MessagePushEventImpl(SMS, assigners, noticeConf, processInstanceId,
                tenantId, taskId);
        return newEvent;
    }
}
