package cn.stylefeng.workflow.instance.core.actions.approver;


import cn.stylefeng.workflow.api.entity.design.Node;
import cn.stylefeng.workflow.api.entity.instance.RuntimeNode;
import cn.stylefeng.workflow.api.enums.NodeTypeEnum;
import cn.stylefeng.workflow.api.pojo.InstanceContext;
import cn.stylefeng.workflow.instance.api.node.NodeAction;
import cn.stylefeng.workflow.instance.api.pojo.NodeActionResult;
import cn.stylefeng.workflow.instance.modular.task.service.RuTaskService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class CopyToNodeAction extends NodeAction {

    @Resource
    private RuTaskService ruTaskService;

    @Override
    public NodeTypeEnum getNodeType() {
        return NodeTypeEnum.COPY_TO;
    }

    @Override
    public NodeActionResult doAction(Node nodeInfo, InstanceContext instanceContext) {

        RuntimeNode thisRuntimeNode = super.createAndSaveRuntimeNode(nodeInfo, instanceContext);

        ruTaskService.createWaitToReadTask(nodeInfo, thisRuntimeNode, instanceContext);

        List<Node> nodes = super.calcNextNodeList(nodeInfo, instanceContext);

        return new NodeActionResult(thisRuntimeNode, nodes, instanceContext.getInstanceVariable());
    }

}
