package cn.stylefeng.workflow.instance.modular.draft.factory;

import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.workflow.instance.api.pojo.task.CommonTaskItem;
import cn.stylefeng.workflow.instance.modular.draft.entity.FlowEngineDraft;

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

public class DraftFactory {

    public static List<CommonTaskItem> createDraftResult(List<FlowEngineDraft> list) {

        if (ObjectUtil.isEmpty(list)) {
            return new ArrayList<>();
        }

        List<CommonTaskItem> result = new ArrayList<>();
        list.forEach(flowEngineDraft -> {
            CommonTaskItem commonTaskItem = new CommonTaskItem();
            commonTaskItem.setId(flowEngineDraft.getDraftId());
            commonTaskItem.setDefinitionId(flowEngineDraft.getDefinitionId());
            commonTaskItem.setInstanceTitle(flowEngineDraft.getDraftTitle());
            commonTaskItem.setApplicant(flowEngineDraft.getApplicant());
            commonTaskItem.setApplicantOrgId(flowEngineDraft.getApplicantOrgId());
            commonTaskItem.setCreateTime(flowEngineDraft.getCreateTime());
            result.add(commonTaskItem);
        });

        return result;
    }

}
