package com.lanyuanxiaoyao.leopard.server.service.task;

import com.lanyuanxiaoyao.leopard.server.service.TaskService;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.exception.NoSuchContextBeanException;

public abstract class TaskNodeComponent extends NodeComponent {
  private final TaskService taskService;

  protected TaskNodeComponent(TaskService taskService) {
    this.taskService = taskService;
  }

  protected void setStep(int step) {
    if (step < 0 || step > 100) {
      throw new IllegalArgumentException("step must be between 0 and 100");
    }
    try {
      var context = getContextBean(TaskMonitorNodes.TaskMonitorContext.class);
      taskService.updateStepById(step, context.getTaskId());
    } catch (NoSuchContextBeanException ignored) {
    }
  }
}
