package cn.axzo.workflow.core.deletage;

import cn.axzo.workflow.common.enums.ApproverSpecifyEnum;
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskDelegateAssigner;
import cn.axzo.workflow.core.common.utils.BpmnMetaParserHelper;
import com.alibaba.fastjson.JSON;
import org.flowable.bpmn.model.UserTask;
import org.flowable.engine.delegate.DelegateExecution;
import org.springframework.stereotype.Component;

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

/**
 * 基于"固定人元"查询审批人
 *
 * @author wangli
 * @since 2023/11/18 22:56
 */
@Component
public class FixedPersonTaskAssigneeSelector extends AbstractBpmnTaskAssigneeSelector {
    @Override
    public boolean support(String param) {
        return ApproverSpecifyEnum.fixedPerson.getType().equals(param);
    }

    @Override
    public List<BpmnTaskDelegateAssigner> select(UserTask userTask, DelegateExecution execution) {
        List<BpmnTaskDelegateAssigner> assigners = new ArrayList<>();
        BpmnMetaParserHelper.getApproverSpecifyValue(userTask)
                .ifPresent(list -> list.forEach(i -> assigners.add(JSON.parseObject(i,
                        BpmnTaskDelegateAssigner.class))));
        return assigners;
    }

}
