package cn.stylefeng.workflow.instance.modular.task.taskopt.impl;

import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
import cn.stylefeng.workflow.api.entity.task.RuTask;
import cn.stylefeng.workflow.instance.api.pojo.task.RuTaskRequest;
import cn.stylefeng.workflow.instance.modular.task.pojo.operate.BatchReadTaskRequest;
import cn.stylefeng.workflow.instance.modular.task.pojo.operate.ReadTaskRequest;
import cn.stylefeng.workflow.instance.modular.task.service.RuTaskService;
import cn.stylefeng.workflow.instance.modular.task.service.TaskDaoWithEvent;
import cn.stylefeng.workflow.instance.modular.task.taskopt.TaskReadService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class TaskReadServiceImpl implements TaskReadService {

    @Resource
    private RuTaskService ruTaskService;

    @Resource
    private TaskDaoWithEvent taskDaoWithEvent;

    @Override
    public void taskRead(ReadTaskRequest readTaskRequest) {
        RuTaskRequest ruTaskRequest = new RuTaskRequest();
        ruTaskRequest.setTaskId(readTaskRequest.getTaskId());
        RuTask ruTask = this.ruTaskService.detail(ruTaskRequest);
        taskDaoWithEvent.updateReadFlag(ruTask, YesOrNotEnum.Y.getCode());
    }

    @Override
    public void batchRead(BatchReadTaskRequest batchReadTaskRequest) {
        for (Long taskId : batchReadTaskRequest.getTaskIdList()) {
            ReadTaskRequest readTaskRequest = new ReadTaskRequest();
            readTaskRequest.setTaskId(taskId);
            this.taskRead(readTaskRequest);
        }
    }

}
