package cn.stylefeng.workflow.instance.modular.task.strategy.emptyprocess;

import cn.stylefeng.workflow.api.entity.design.Node;
import cn.stylefeng.workflow.api.entity.instance.RuntimeNode;
import cn.stylefeng.workflow.api.enums.TaskTypeEnum;
import cn.stylefeng.workflow.api.enums.strategy.EmptyApproverStrategyEnum;
import cn.stylefeng.workflow.api.pojo.InstanceContext;
import cn.stylefeng.workflow.instance.modular.task.service.RuTaskService;
import cn.stylefeng.workflow.instance.modular.task.strategy.emptyprocess.base.EmptyApproverRule;
import cn.stylefeng.workflow.log.api.WorkflowLogApi;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class FlowCreatePersonRule implements EmptyApproverRule {

    @Resource
    private RuTaskService ruTaskService;

    @Resource
    private WorkflowLogApi workflowLogApi;


    @Override
    public EmptyApproverStrategyEnum getStrategyType() {
        return EmptyApproverStrategyEnum.FLOW_CREATE_PERSON;
    }

    @Override
    public void processEmptyApprover(Node currentNode, InstanceContext instanceContext, RuntimeNode runtimeNode) {

        Long createUserId = instanceContext.getRuntimeInstance().getApplicant();

        ruTaskService.createUserTask(createUserId, TaskTypeEnum.PROCESSING, runtimeNode, instanceContext);

        workflowLogApi.logSuccess(instanceContext, currentNode.getNodeId(), "执行审批策略-审批人为空时，由流程创建人替代");

    }

}
