package com.ningdatech.pmapi.projectlib.handle;

import com.ningdatech.pmapi.projectlib.model.vo.ProcessDetailVO;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;

/**
 * 流程执行链
 *
 * @author CMM
 * @since 2023/02/26 21:36
 */
@Component
public class ProcessExecuteChainHandle {

    /**
     * 具体处理者的集合
     */
    private final List<AbstractProcessBusinessHandle> processBusinessHandles;

    public ProcessExecuteChainHandle(List<AbstractProcessBusinessHandle> processBusinessHandles) {
        this.processBusinessHandles = processBusinessHandles;
    }

    /**
     * 遍历处理链，通过前缀判断能否处理逻辑，如果不能继续遍历
     * @param projectId
     * @return void
     * @author CMM
     * @since 2023/02/26
     */
    public List<ProcessDetailVO> handle(Long projectId, List<ProcessDetailVO> processSchedule){
        if (processBusinessHandles.size() > 0) {
            for (AbstractProcessBusinessHandle processBusinessHandle : processBusinessHandles) {
                processBusinessHandle.businessHandle(projectId, processSchedule);
            }
            return processSchedule;
        }
        return Collections.emptyList();
    }
}
