package cn.axzo.workflow.server.controller.delegate;

import cn.axzo.workflow.common.enums.ApproverSpecifyEnum;
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskDelegateAssigner;
import lombok.extern.slf4j.Slf4j;
import org.flowable.bpmn.model.FlowElement;
import org.flowable.engine.delegate.DelegateExecution;
import org.springframework.stereotype.Component;

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

import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_INITIATOR;

/**
 * 基于发起自己的任务审批人选择器
 *
 * @author wangli
 * @since 2025-08-18 14:54
 */
@Slf4j
@Component
public class BasedInitiatorV2TaskAssigneeSelector extends AbstractBpmnTaskAssigneeSelector {
    @Override
    public String getType() {
        return ApproverSpecifyEnum.initiator_v2.getType();
    }

    @Override
    public List<BpmnTaskDelegateAssigner> select(FlowElement flowElement, DelegateExecution execution, Boolean throwException) {
        // 获取发起人
        BpmnTaskDelegateAssigner initiator =
                BpmnTaskDelegateAssigner.toObjectCompatible(execution.getVariables().get(INTERNAL_INITIATOR));
        return Collections.singletonList(initiator);
    }
}
